From 2e599971cca95a7c62b46e97c45bf98c3f2f2f12 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 20 Mar 2023 16:39:00 -0400 Subject: [PATCH] fix(striker-ui-api): add DELETE one or more manifest --- .../manifest/deleteManifest.ts | 37 +++++++++++++++++++ .../lib/request_handlers/manifest/index.ts | 1 + striker-ui-api/src/routes/manifest.ts | 5 ++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 striker-ui-api/src/lib/request_handlers/manifest/deleteManifest.ts 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;