fix(striker-ui-api): change response format for GET /server

main
Tsu-ba-me 2 years ago
parent 2c967b1a7f
commit 26a64ecb2f
  1. 25
      striker-ui-api/src/lib/request_handlers/server/getServer.ts
  2. 6
      striker-ui-api/src/types/ServerOverview.d.ts

@ -1,7 +1,8 @@
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import join from '../../join'; import join from '../../join';
export const getServer = buildGetRequestHandler((request) => { export const getServer = buildGetRequestHandler(
(request, buildQueryOptions) => {
const { anvilsUUID } = request.body; const { anvilsUUID } = request.body;
const condAnvilsUUID = join(anvilsUUID, { const condAnvilsUUID = join(anvilsUUID, {
@ -13,6 +14,25 @@ export const getServer = buildGetRequestHandler((request) => {
console.log(`condAnvilsUUID=[${condAnvilsUUID}]`); console.log(`condAnvilsUUID=[${condAnvilsUUID}]`);
if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => {
let result = queryStdout;
if (queryStdout instanceof Array) {
result = queryStdout.map<ServerOverview>(
([serverUUID, serverName, serverState, serverHostUUID]) => ({
serverHostUUID,
serverName,
serverState,
serverUUID,
}),
);
}
return result;
};
}
return ` return `
SELECT SELECT
server_uuid, server_uuid,
@ -22,4 +42,5 @@ export const getServer = buildGetRequestHandler((request) => {
FROM servers FROM servers
WHERE server_state != 'DELETED' WHERE server_state != 'DELETED'
${condAnvilsUUID};`; ${condAnvilsUUID};`;
}); },
);

@ -0,0 +1,6 @@
type ServerOverview = {
serverHostUUID: string;
serverName: string;
serverState: string;
serverUUID: string;
};
Loading…
Cancel
Save