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 buildGetRequestHandler from '../buildGetRequestHandler';
import join from '../../join'; import join from '../../join';
export const getServer = buildGetRequestHandler((request) => { export const getServer = buildGetRequestHandler(
const { anvilsUUID } = request.body; (request, buildQueryOptions) => {
const { anvilsUUID } = request.body;
const condAnvilsUUID = join(anvilsUUID, { const condAnvilsUUID = join(anvilsUUID, {
beforeReturn: (toReturn) => beforeReturn: (toReturn) =>
toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '', toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '',
elementWrapper: "'", elementWrapper: "'",
separator: ', ', 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 SELECT
server_uuid, server_uuid,
server_name, server_name,
@ -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