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;