parent
5de6046715
commit
b7b4e13028
5 changed files with 78 additions and 7 deletions
@ -0,0 +1,29 @@ |
|||||||
|
import { AssertionError } from 'assert'; |
||||||
|
import { RequestHandler } from 'express'; |
||||||
|
|
||||||
|
import { buildManifest } from './buildManifest'; |
||||||
|
import { stderr } from '../../shell'; |
||||||
|
|
||||||
|
export const createManifest: RequestHandler = (...handlerArgs) => { |
||||||
|
const [, response] = handlerArgs; |
||||||
|
|
||||||
|
let result: Record<string, string> = {}; |
||||||
|
|
||||||
|
try { |
||||||
|
result = buildManifest(...handlerArgs); |
||||||
|
} catch (buildError) { |
||||||
|
stderr(`Failed to create new install manifest; CAUSE ${buildError}`); |
||||||
|
|
||||||
|
let code = 500; |
||||||
|
|
||||||
|
if (buildError instanceof AssertionError) { |
||||||
|
code = 400; |
||||||
|
} |
||||||
|
|
||||||
|
response.status(code).send(); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
response.status(201).send(result); |
||||||
|
}; |
@ -1,4 +1,6 @@ |
|||||||
|
export * from './createManifest'; |
||||||
export * from './deleteManifest'; |
export * from './deleteManifest'; |
||||||
export * from './getManifest'; |
export * from './getManifest'; |
||||||
export * from './getManifestDetail'; |
export * from './getManifestDetail'; |
||||||
export * from './getManifestTemplate'; |
export * from './getManifestTemplate'; |
||||||
|
export * from './updateManifest'; |
||||||
|
@ -0,0 +1,34 @@ |
|||||||
|
import { AssertionError } from 'assert'; |
||||||
|
import { RequestHandler } from 'express'; |
||||||
|
|
||||||
|
import { buildManifest } from './buildManifest'; |
||||||
|
import { stderr } from '../../shell'; |
||||||
|
|
||||||
|
export const updateManifest: RequestHandler = (...args) => { |
||||||
|
const [request, response] = args; |
||||||
|
const { |
||||||
|
params: { manifestUuid }, |
||||||
|
} = request; |
||||||
|
|
||||||
|
let result: Record<string, string> = {}; |
||||||
|
|
||||||
|
try { |
||||||
|
result = buildManifest(...args); |
||||||
|
} catch (buildError) { |
||||||
|
stderr( |
||||||
|
`Failed to update install manifest ${manifestUuid}; CAUSE: ${buildError}`, |
||||||
|
); |
||||||
|
|
||||||
|
let code = 500; |
||||||
|
|
||||||
|
if (buildError instanceof AssertionError) { |
||||||
|
code = 400; |
||||||
|
} |
||||||
|
|
||||||
|
response.status(code).send(); |
||||||
|
|
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
response.status(200).send(result); |
||||||
|
}; |
@ -1,19 +1,23 @@ |
|||||||
import express from 'express'; |
import express from 'express'; |
||||||
|
|
||||||
import { |
import { |
||||||
|
createManifest, |
||||||
deleteManifest, |
deleteManifest, |
||||||
getManifest, |
getManifest, |
||||||
getManifestDetail, |
getManifestDetail, |
||||||
getManifestTemplate, |
getManifestTemplate, |
||||||
|
updateManifest, |
||||||
} from '../lib/request_handlers/manifest'; |
} from '../lib/request_handlers/manifest'; |
||||||
|
|
||||||
const router = express.Router(); |
const router = express.Router(); |
||||||
|
|
||||||
router |
router |
||||||
|
.delete('/', deleteManifest) |
||||||
|
.delete('/manifestUuid', deleteManifest) |
||||||
.get('/', getManifest) |
.get('/', getManifest) |
||||||
.get('/template', getManifestTemplate) |
.get('/template', getManifestTemplate) |
||||||
.get('/:manifestUUID', getManifestDetail) |
.get('/:manifestUUID', getManifestDetail) |
||||||
.delete('/', deleteManifest) |
.post('/', createManifest) |
||||||
.delete('/manifestUuid', deleteManifest); |
.put('/:manifestUuid', updateManifest); |
||||||
|
|
||||||
export default router; |
export default router; |
||||||
|
Loading…
Reference in new issue