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

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

@ -1,19 +1,39 @@
import buildGetRequestHandler from '../buildGetRequestHandler';
import join from '../../join';
export const getServer = buildGetRequestHandler((request) => {
const { anvilsUUID } = request.body;
export const getServer = buildGetRequestHandler(
(request, buildQueryOptions) => {
const { anvilsUUID } = request.body;
const condAnvilsUUID = join(anvilsUUID, {
beforeReturn: (toReturn) =>
toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '',
elementWrapper: "'",
separator: ', ',
});
const condAnvilsUUID = join(anvilsUUID, {
beforeReturn: (toReturn) =>
toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '',
elementWrapper: "'",
separator: ', ',
});
console.log(`condAnvilsUUID=[${condAnvilsUUID}]`);
console.log(`condAnvilsUUID=[${condAnvilsUUID}]`);
return `
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 `
SELECT
server_uuid,
server_name,
@ -22,4 +42,5 @@ export const getServer = buildGetRequestHandler((request) => {
FROM servers
WHERE server_state != 'DELETED'
${condAnvilsUUID};`;
});
},
);

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