fix(striker-ui-api): add delete endpoint for /fence

main
Tsu-ba-me 2 years ago
parent 7414553dae
commit 78d7ce90b9
  1. 20
      striker-ui-api/src/lib/request_handlers/fence/deleteFence.ts
  2. 1
      striker-ui-api/src/lib/request_handlers/fence/index.ts
  3. 11
      striker-ui-api/src/routes/fence.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}`);
},
});

@ -1,2 +1,3 @@
export * from './deleteFence';
export * from './getFence'; export * from './getFence';
export * from './getFenceTemplate'; export * from './getFenceTemplate';

@ -1,9 +1,16 @@
import express from 'express'; 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(); const router = express.Router();
router.get('/', getFence).get('/template', getFenceTemplate); router
.delete('/:uuid?', deleteFence)
.get('/', getFence)
.get('/template', getFenceTemplate);
export default router; export default router;

Loading…
Cancel
Save