From 78d7ce90b91c16ca5a6ed99c1cff3b6224a0b776 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 28 Jun 2023 04:14:18 -0400 Subject: [PATCH] fix(striker-ui-api): add delete endpoint for /fence --- .../lib/request_handlers/fence/deleteFence.ts | 20 +++++++++++++++++++ .../src/lib/request_handlers/fence/index.ts | 1 + striker-ui-api/src/routes/fence.ts | 11 ++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 striker-ui-api/src/lib/request_handlers/fence/deleteFence.ts diff --git a/striker-ui-api/src/lib/request_handlers/fence/deleteFence.ts b/striker-ui-api/src/lib/request_handlers/fence/deleteFence.ts new file mode 100644 index 00000000..3510f074 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/fence/deleteFence.ts @@ -0,0 +1,20 @@ +import { DELETED } from '../../consts'; + +import { write } from '../../accessModule'; +import { buildDeleteRequestHandler } from '../buildDeleteRequestHandler'; +import join from '../../join'; + +export const deleteFence = buildDeleteRequestHandler({ + delete: async (fenceUuids) => { + const wcode = await write( + `UPDATE fences + SET fence_arguments = '${DELETED}' + WHERE fence_uuid IN (${join(fenceUuids, { + elementWrapper: "'", + separator: ',', + })});`, + ); + + if (wcode !== 0) throw Error(`Write exited with code ${wcode}`); + }, +}); diff --git a/striker-ui-api/src/lib/request_handlers/fence/index.ts b/striker-ui-api/src/lib/request_handlers/fence/index.ts index 9bdff0fc..8c5ca77f 100644 --- a/striker-ui-api/src/lib/request_handlers/fence/index.ts +++ b/striker-ui-api/src/lib/request_handlers/fence/index.ts @@ -1,2 +1,3 @@ +export * from './deleteFence'; export * from './getFence'; export * from './getFenceTemplate'; diff --git a/striker-ui-api/src/routes/fence.ts b/striker-ui-api/src/routes/fence.ts index 0df4f266..f502ce12 100644 --- a/striker-ui-api/src/routes/fence.ts +++ b/striker-ui-api/src/routes/fence.ts @@ -1,9 +1,16 @@ import express from 'express'; -import { getFence, getFenceTemplate } from '../lib/request_handlers/fence'; +import { + deleteFence, + getFence, + getFenceTemplate, +} from '../lib/request_handlers/fence'; const router = express.Router(); -router.get('/', getFence).get('/template', getFenceTemplate); +router + .delete('/:uuid?', deleteFence) + .get('/', getFence) + .get('/template', getFenceTemplate); export default router;