fix(striker-ui-api): add GET UPS overviews

main
Tsu-ba-me 2 years ago committed by digimer
parent d408b22f24
commit 84fb75f5e1
  1. 37
      striker-ui-api/src/lib/request_handlers/ups/getUPS.ts
  2. 1
      striker-ui-api/src/lib/request_handlers/ups/index.ts
  3. 4
      striker-ui-api/src/routes/ups.ts
  4. 6
      striker-ui-api/src/types/APIUPS.d.ts

@ -0,0 +1,37 @@
import { RequestHandler } from 'express';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
export const getUPS: RequestHandler = buildGetRequestHandler(
(request, buildQueryOptions) => {
const query = `
SELECT
ups_uuid,
ups_name,
ups_agent,
ups_ip_address
FROM upses
ORDER BY ups_name ASC;`;
const afterQueryReturn: QueryResultModifierFunction | undefined =
buildQueryResultReducer<{ [upsUUID: string]: UPSOverview }>(
(previous, [upsUUID, upsName, upsAgent, upsIPAddress]) => {
previous[upsUUID] = {
upsAgent,
upsIPAddress,
upsName,
upsUUID,
};
return previous;
},
{},
);
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = afterQueryReturn;
}
return query;
},
);

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

@ -1,9 +1,9 @@
import express from 'express';
import { getUPSTemplate } from '../lib/request_handlers/ups';
import { getUPS, getUPSTemplate } from '../lib/request_handlers/ups';
const router = express.Router();
router.get('/template', getUPSTemplate);
router.get('/', getUPS).get('/template', getUPSTemplate);
export default router;

@ -0,0 +1,6 @@
type UPSOverview = {
upsAgent: string;
upsIPAddress: string;
upsName: string;
upsUUID: string;
};
Loading…
Cancel
Save