From 84fb75f5e1420baae8ab10c0d5720d62ff25464d Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 28 Feb 2023 23:22:07 -0500 Subject: [PATCH] fix(striker-ui-api): add GET UPS overviews --- .../src/lib/request_handlers/ups/getUPS.ts | 37 +++++++++++++++++++ .../src/lib/request_handlers/ups/index.ts | 1 + striker-ui-api/src/routes/ups.ts | 4 +- striker-ui-api/src/types/APIUPS.d.ts | 6 +++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 striker-ui-api/src/lib/request_handlers/ups/getUPS.ts create mode 100644 striker-ui-api/src/types/APIUPS.d.ts diff --git a/striker-ui-api/src/lib/request_handlers/ups/getUPS.ts b/striker-ui-api/src/lib/request_handlers/ups/getUPS.ts new file mode 100644 index 00000000..e884e54f --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/ups/getUPS.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; + }, +); 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 969616cb..191a8f79 100644 --- a/striker-ui-api/src/lib/request_handlers/ups/index.ts +++ b/striker-ui-api/src/lib/request_handlers/ups/index.ts @@ -1 +1,2 @@ +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 1d19b86f..c6e6c637 100644 --- a/striker-ui-api/src/routes/ups.ts +++ b/striker-ui-api/src/routes/ups.ts @@ -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; diff --git a/striker-ui-api/src/types/APIUPS.d.ts b/striker-ui-api/src/types/APIUPS.d.ts new file mode 100644 index 00000000..4eb25534 --- /dev/null +++ b/striker-ui-api/src/types/APIUPS.d.ts @@ -0,0 +1,6 @@ +type UPSOverview = { + upsAgent: string; + upsIPAddress: string; + upsName: string; + upsUUID: string; +};