parent
d408b22f24
commit
84fb75f5e1
4 changed files with 46 additions and 2 deletions
@ -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'; |
export * from './getUPSTemplate'; |
||||||
|
@ -1,9 +1,9 @@ |
|||||||
import express from 'express'; |
import express from 'express'; |
||||||
|
|
||||||
import { getUPSTemplate } from '../lib/request_handlers/ups'; |
import { getUPS, getUPSTemplate } from '../lib/request_handlers/ups'; |
||||||
|
|
||||||
const router = express.Router(); |
const router = express.Router(); |
||||||
|
|
||||||
router.get('/template', getUPSTemplate); |
router.get('/', getUPS).get('/template', getUPSTemplate); |
||||||
|
|
||||||
export default router; |
export default router; |
||||||
|
@ -0,0 +1,6 @@ |
|||||||
|
type UPSOverview = { |
||||||
|
upsAgent: string; |
||||||
|
upsIPAddress: string; |
||||||
|
upsName: string; |
||||||
|
upsUUID: string; |
||||||
|
}; |
Loading…
Reference in new issue