feat(striker-ui-api): add /servers route

main
Tsu-ba-me 3 years ago
parent 49fdc9cad4
commit c352fc5f0e
  1. 4
      striker-ui-api/src/app.ts
  2. 27
      striker-ui-api/src/lib/request_handlers/servers/getServers.ts
  3. 5
      striker-ui-api/src/routes/index.ts
  4. 9
      striker-ui-api/src/routes/servers.ts

@ -4,8 +4,7 @@ import path from 'path';
import API_ROOT_PATH from './lib/consts/API_ROOT_PATH'; import API_ROOT_PATH from './lib/consts/API_ROOT_PATH';
import echoRouter from './routes/echo'; import { echoRouter, filesRouter, serversRouter } from './routes';
import filesRouter from './routes/files';
const app = express(); 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, 'echo'), echoRouter);
app.use(path.join(API_ROOT_PATH, 'files'), filesRouter); app.use(path.join(API_ROOT_PATH, 'files'), filesRouter);
app.use(path.join(API_ROOT_PATH, 'servers'), serversRouter);
export default app; export default app;

@ -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;

@ -0,0 +1,5 @@
import echoRouter from './echo';
import filesRouter from './files';
import serversRouter from './servers';
export { echoRouter, filesRouter, serversRouter };

@ -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;
Loading…
Cancel
Save