diff --git a/striker-ui-api/src/lib/request_handlers/manifest/deleteManifest.ts b/striker-ui-api/src/lib/request_handlers/manifest/deleteManifest.ts new file mode 100644 index 00000000..0ba2d14b --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/manifest/deleteManifest.ts @@ -0,0 +1,37 @@ +import { RequestHandler } from 'express'; + +import { sub } from '../../accessModule'; +import { stderr, stdout } from '../../shell'; + +export const deleteManifest: RequestHandler< + { manifestUuid: string }, + undefined, + { uuids: string[] } +> = (request, response) => { + const { + params: { manifestUuid: rawManifestUuid }, + body: { uuids: rawManifestUuidList } = {}, + } = request; + + const manifestUuidList: string[] = rawManifestUuidList + ? rawManifestUuidList + : [rawManifestUuid]; + + manifestUuidList.forEach((uuid) => { + stdout(`Begin delete manifest ${uuid}.`); + + try { + sub('insert_or_update_manifests', { + subParams: { delete: 1, manifest_uuid: uuid }, + }); + } catch (subError) { + stderr(`Failed to delete manifest ${uuid}; CAUSE: ${subError}`); + + response.status(500).send(); + + return; + } + }); + + response.status(204).send(); +}; diff --git a/striker-ui-api/src/lib/request_handlers/manifest/index.ts b/striker-ui-api/src/lib/request_handlers/manifest/index.ts index 93271202..5b9845b3 100644 --- a/striker-ui-api/src/lib/request_handlers/manifest/index.ts +++ b/striker-ui-api/src/lib/request_handlers/manifest/index.ts @@ -1,3 +1,4 @@ +export * from './deleteManifest'; export * from './getManifest'; export * from './getManifestDetail'; export * from './getManifestTemplate'; diff --git a/striker-ui-api/src/routes/manifest.ts b/striker-ui-api/src/routes/manifest.ts index e68bca88..4b462bc9 100644 --- a/striker-ui-api/src/routes/manifest.ts +++ b/striker-ui-api/src/routes/manifest.ts @@ -1,6 +1,7 @@ import express from 'express'; import { + deleteManifest, getManifest, getManifestDetail, getManifestTemplate, @@ -11,6 +12,8 @@ const router = express.Router(); router .get('/', getManifest) .get('/template', getManifestTemplate) - .get('/:manifestUUID', getManifestDetail); + .get('/:manifestUUID', getManifestDetail) + .delete('/', deleteManifest) + .delete('/manifestUuid', deleteManifest); export default router;