fix(striker-ui-api): add delete UPS(es), don't get deleted UPS(es)

main
Tsu-ba-me 2 years ago
parent 58a867f010
commit 63dafe0e6a
  1. 20
      striker-ui-api/src/lib/request_handlers/ups/deleteUps.ts
  2. 3
      striker-ui-api/src/lib/request_handlers/ups/getUPS.ts
  3. 1
      striker-ui-api/src/lib/request_handlers/ups/index.ts
  4. 7
      striker-ui-api/src/routes/ups.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}`);
},
});

@ -1,5 +1,7 @@
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { DELETED } from '../../consts';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier'; import { buildQueryResultReducer } from '../../buildQueryResultModifier';
@ -12,6 +14,7 @@ export const getUPS: RequestHandler = buildGetRequestHandler(
ups_agent, ups_agent,
ups_ip_address ups_ip_address
FROM upses FROM upses
WHERE ups_ip_address != '${DELETED}'
ORDER BY ups_name ASC;`; ORDER BY ups_name ASC;`;
const afterQueryReturn: QueryResultModifierFunction | undefined = const afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [upsUUID: string]: UpsOverview }>( buildQueryResultReducer<{ [upsUUID: string]: UpsOverview }>(

@ -1,2 +1,3 @@
export * from './deleteUps';
export * from './getUPS'; export * from './getUPS';
export * from './getUPSTemplate'; export * from './getUPSTemplate';

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

Loading…
Cancel
Save