diff --git a/striker-ui-api/src/lib/request_handlers/manifest/getManifest.ts b/striker-ui-api/src/lib/request_handlers/manifest/getManifest.ts new file mode 100644 index 00000000..bf0ce4e6 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/manifest/getManifest.ts @@ -0,0 +1,33 @@ +import { RequestHandler } from 'express'; + +import buildGetRequestHandler from '../buildGetRequestHandler'; +import { buildQueryResultReducer } from '../../buildQueryResultModifier'; + +export const getManifest: RequestHandler = buildGetRequestHandler( + (response, buildQueryOptions) => { + const query = ` + SELECT + manifest_uuid, + manifest_name + FROM manifests + ORDER BY manifest_name ASC;`; + const afterQueryReturn: QueryResultModifierFunction | undefined = + buildQueryResultReducer<{ [manifestUUID: string]: ManifestOverview }>( + (previous, [manifestUUID, manifestName]) => { + previous[manifestUUID] = { + manifestName, + manifestUUID, + }; + + return previous; + }, + {}, + ); + + if (buildQueryOptions) { + buildQueryOptions.afterQueryReturn = afterQueryReturn; + } + + return query; + }, +); diff --git a/striker-ui-api/src/lib/request_handlers/manifest/index.ts b/striker-ui-api/src/lib/request_handlers/manifest/index.ts new file mode 100644 index 00000000..79e54734 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/manifest/index.ts @@ -0,0 +1 @@ +export * from './getManifest'; diff --git a/striker-ui-api/src/routes/index.ts b/striker-ui-api/src/routes/index.ts index 618e952c..ef703777 100644 --- a/striker-ui-api/src/routes/index.ts +++ b/striker-ui-api/src/routes/index.ts @@ -7,6 +7,7 @@ import fenceRouter from './fence'; import fileRouter from './file'; import hostRouter from './host'; import jobRouter from './job'; +import manifestRouter from './manifest'; import networkInterfaceRouter from './network-interface'; import serverRouter from './server'; import sshKeyRouter from './ssh-key'; @@ -21,6 +22,7 @@ const routes: Readonly> = { file: fileRouter, host: hostRouter, job: jobRouter, + manifest: manifestRouter, 'network-interface': networkInterfaceRouter, server: serverRouter, 'ssh-key': sshKeyRouter, diff --git a/striker-ui-api/src/routes/manifest.ts b/striker-ui-api/src/routes/manifest.ts new file mode 100644 index 00000000..2502a183 --- /dev/null +++ b/striker-ui-api/src/routes/manifest.ts @@ -0,0 +1,9 @@ +import express from 'express'; + +import { getManifest } from '../lib/request_handlers/manifest'; + +const router = express.Router(); + +router.get('/', getManifest); + +export default router; diff --git a/striker-ui-api/src/types/APIManifest.d.ts b/striker-ui-api/src/types/APIManifest.d.ts new file mode 100644 index 00000000..0e846a90 --- /dev/null +++ b/striker-ui-api/src/types/APIManifest.d.ts @@ -0,0 +1,4 @@ +type ManifestOverview = { + manifestName: string; + manifestUUID: string; +};