diff --git a/striker-ui-api/src/lib/request_handlers/ups/deleteUps.ts b/striker-ui-api/src/lib/request_handlers/ups/deleteUps.ts new file mode 100644 index 00000000..af8360bf --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/ups/deleteUps.ts @@ -0,0 +1,20 @@ +import { DELETED } from '../../consts'; + +import { write } from '../../accessModule'; +import { buildDeleteRequestHandler } from '../buildDeleteRequestHandler'; +import join from '../../join'; + +export const deleteUps = buildDeleteRequestHandler({ + delete: async (upsUuids) => { + const wcode = await write( + `UPDATE upses + SET ups_ip_address = '${DELETED}' + WHERE ups_uuid IN (${join(upsUuids, { + elementWrapper: "'", + separator: ',', + })});`, + ); + + if (wcode !== 0) throw Error(`Write exited with code ${wcode}`); + }, +}); diff --git a/striker-ui-api/src/lib/request_handlers/ups/getUPS.ts b/striker-ui-api/src/lib/request_handlers/ups/getUPS.ts index 099cdbc8..75ad6336 100644 --- a/striker-ui-api/src/lib/request_handlers/ups/getUPS.ts +++ b/striker-ui-api/src/lib/request_handlers/ups/getUPS.ts @@ -1,5 +1,7 @@ import { RequestHandler } from 'express'; +import { DELETED } from '../../consts'; + import buildGetRequestHandler from '../buildGetRequestHandler'; import { buildQueryResultReducer } from '../../buildQueryResultModifier'; @@ -12,6 +14,7 @@ export const getUPS: RequestHandler = buildGetRequestHandler( ups_agent, ups_ip_address FROM upses + WHERE ups_ip_address != '${DELETED}' ORDER BY ups_name ASC;`; const afterQueryReturn: QueryResultModifierFunction | undefined = buildQueryResultReducer<{ [upsUUID: string]: UpsOverview }>( diff --git a/striker-ui-api/src/lib/request_handlers/ups/index.ts b/striker-ui-api/src/lib/request_handlers/ups/index.ts index 191a8f79..ad64d4e9 100644 --- a/striker-ui-api/src/lib/request_handlers/ups/index.ts +++ b/striker-ui-api/src/lib/request_handlers/ups/index.ts @@ -1,2 +1,3 @@ +export * from './deleteUps'; export * from './getUPS'; export * from './getUPSTemplate'; diff --git a/striker-ui-api/src/routes/ups.ts b/striker-ui-api/src/routes/ups.ts index c6e6c637..f93ca5cd 100644 --- a/striker-ui-api/src/routes/ups.ts +++ b/striker-ui-api/src/routes/ups.ts @@ -1,9 +1,12 @@ import express from 'express'; -import { getUPS, getUPSTemplate } from '../lib/request_handlers/ups'; +import { deleteUps, getUPS, getUPSTemplate } from '../lib/request_handlers/ups'; const router = express.Router(); -router.get('/', getUPS).get('/template', getUPSTemplate); +router + .delete('/:uuid?', deleteUps) + .get('/', getUPS) + .get('/template', getUPSTemplate); export default router;