From df77899be19265998d07d49edd1147558317b991 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 7 Nov 2022 17:43:41 -0500 Subject: [PATCH] fix(striker-ui-api): add /user --- .../src/lib/request_handlers/user/getUser.ts | 27 +++++++++++++++++++ .../src/lib/request_handlers/user/index.ts | 1 + striker-ui-api/src/routes/index.ts | 2 ++ striker-ui-api/src/routes/user.ts | 9 +++++++ 4 files changed, 39 insertions(+) create mode 100644 striker-ui-api/src/lib/request_handlers/user/getUser.ts create mode 100644 striker-ui-api/src/lib/request_handlers/user/index.ts create mode 100644 striker-ui-api/src/routes/user.ts diff --git a/striker-ui-api/src/lib/request_handlers/user/getUser.ts b/striker-ui-api/src/lib/request_handlers/user/getUser.ts new file mode 100644 index 00000000..1551ecc8 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/user/getUser.ts @@ -0,0 +1,27 @@ +import buildGetRequestHandler from '../buildGetRequestHandler'; +import { buildQueryResultReducer } from '../../buildQueryResultModifier'; + +export const getUser = buildGetRequestHandler((request, buildQueryOptions) => { + const query = ` + SELECT + use.user_name, + use.user_uuid + FROM users AS use;`; + const afterQueryReturn: QueryResultModifierFunction | undefined = + buildQueryResultReducer< + Record + >((previous, [userName, userUUID]) => { + previous[userUUID] = { + userName, + userUUID, + }; + + return previous; + }, {}); + + if (buildQueryOptions) { + buildQueryOptions.afterQueryReturn = afterQueryReturn; + } + + return query; +}); diff --git a/striker-ui-api/src/lib/request_handlers/user/index.ts b/striker-ui-api/src/lib/request_handlers/user/index.ts new file mode 100644 index 00000000..3f9351e9 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/user/index.ts @@ -0,0 +1 @@ +export * from './getUser'; diff --git a/striker-ui-api/src/routes/index.ts b/striker-ui-api/src/routes/index.ts index 21a59f43..03d8ebc1 100644 --- a/striker-ui-api/src/routes/index.ts +++ b/striker-ui-api/src/routes/index.ts @@ -8,6 +8,7 @@ import hostRouter from './host'; import jobRouter from './job'; import networkInterfaceRouter from './network-interface'; import serverRouter from './server'; +import userRouter from './user'; const routes: Readonly> = { anvil: anvilRouter, @@ -18,6 +19,7 @@ const routes: Readonly> = { job: jobRouter, 'network-interface': networkInterfaceRouter, server: serverRouter, + user: userRouter, }; export default routes; diff --git a/striker-ui-api/src/routes/user.ts b/striker-ui-api/src/routes/user.ts new file mode 100644 index 00000000..a3633efa --- /dev/null +++ b/striker-ui-api/src/routes/user.ts @@ -0,0 +1,9 @@ +import express from 'express'; + +import { getUser } from '../lib/request_handlers/user'; + +const router = express.Router(); + +router.get('/', getUser); + +export default router;