From c352fc5f0eba58970d5247f4310b587f44d1c8e8 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 24 Mar 2022 16:38:07 -0400 Subject: [PATCH] feat(striker-ui-api): add /servers route --- striker-ui-api/src/app.ts | 4 +-- .../request_handlers/servers/getServers.ts | 27 +++++++++++++++++++ striker-ui-api/src/routes/index.ts | 5 ++++ striker-ui-api/src/routes/servers.ts | 9 +++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 striker-ui-api/src/lib/request_handlers/servers/getServers.ts create mode 100644 striker-ui-api/src/routes/index.ts create mode 100644 striker-ui-api/src/routes/servers.ts diff --git a/striker-ui-api/src/app.ts b/striker-ui-api/src/app.ts index 6dc85195..9b033fdb 100644 --- a/striker-ui-api/src/app.ts +++ b/striker-ui-api/src/app.ts @@ -4,8 +4,7 @@ import path from 'path'; import API_ROOT_PATH from './lib/consts/API_ROOT_PATH'; -import echoRouter from './routes/echo'; -import filesRouter from './routes/files'; +import { echoRouter, filesRouter, serversRouter } from './routes'; const app = express(); @@ -14,5 +13,6 @@ app.use(cors()); app.use(path.join(API_ROOT_PATH, 'echo'), echoRouter); app.use(path.join(API_ROOT_PATH, 'files'), filesRouter); +app.use(path.join(API_ROOT_PATH, 'servers'), serversRouter); export default app; diff --git a/striker-ui-api/src/lib/request_handlers/servers/getServers.ts b/striker-ui-api/src/lib/request_handlers/servers/getServers.ts new file mode 100644 index 00000000..ebae0343 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/servers/getServers.ts @@ -0,0 +1,27 @@ +import buildGetRequestHandler from '../buildGetRequestHandler'; +import join from '../../join'; + +const getServers = buildGetRequestHandler((request) => { + const { anvilsUUID } = request.body; + + const condAnvilsUUID = join(anvilsUUID, { + beforeReturn: (toReturn) => + toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '', + elementWrapper: "'", + separator: ', ', + }); + + console.log(`condAnvilsUUID=[${condAnvilsUUID}]`); + + return ` + SELECT + server_uuid, + server_name, + server_state, + server_host_uuid + FROM servers + WHERE server_state != 'DELETED' + ${condAnvilsUUID};`; +}); + +export default getServers; diff --git a/striker-ui-api/src/routes/index.ts b/striker-ui-api/src/routes/index.ts new file mode 100644 index 00000000..2fa05fdc --- /dev/null +++ b/striker-ui-api/src/routes/index.ts @@ -0,0 +1,5 @@ +import echoRouter from './echo'; +import filesRouter from './files'; +import serversRouter from './servers'; + +export { echoRouter, filesRouter, serversRouter }; diff --git a/striker-ui-api/src/routes/servers.ts b/striker-ui-api/src/routes/servers.ts new file mode 100644 index 00000000..24aa8b46 --- /dev/null +++ b/striker-ui-api/src/routes/servers.ts @@ -0,0 +1,9 @@ +import express from 'express'; + +import getServers from '../lib/request_handlers/servers/getServers'; + +const router = express.Router(); + +router.get('/', getServers); + +export default router;