fix(striker-ui-api): get anvil UUIDs from query params in GET /server

main
Tsu-ba-me 3 years ago
parent 4b03be4bc3
commit f476524461
  1. 36
      striker-ui-api/src/lib/request_handlers/server/getServer.ts

@ -1,18 +1,22 @@
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import join from '../../join'; import join from '../../join';
import { sanitizeQS } from '../../sanitizeQS';
export const getServer = buildGetRequestHandler( export const getServer = buildGetRequestHandler(
(request, buildQueryOptions) => { (request, buildQueryOptions) => {
const { anvilsUUID } = request.body; const { anvilUUIDs } = request.query;
const condAnvilsUUID = join(anvilsUUID, { const condAnvilUUIDs = join(
beforeReturn: (toReturn) => sanitizeQS(anvilUUIDs, { returnType: 'string[]' }),
toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '', {
elementWrapper: "'", beforeReturn: (toReturn) =>
separator: ', ', toReturn ? `AND server_anvil_uuid IN (${toReturn})` : '',
}); elementWrapper: "'",
separator: ', ',
},
);
console.log(`condAnvilsUUID=[${condAnvilsUUID}]`); console.log(`condAnvilsUUID=[${condAnvilUUIDs}]`);
if (buildQueryOptions) { if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => { buildQueryOptions.afterQueryReturn = (queryStdout) => {
@ -34,13 +38,13 @@ export const getServer = buildGetRequestHandler(
} }
return ` return `
SELECT SELECT
server_uuid, server_uuid,
server_name, server_name,
server_state, server_state,
server_host_uuid server_host_uuid
FROM servers FROM servers
WHERE server_state != 'DELETED' WHERE server_state != 'DELETED'
${condAnvilsUUID};`; ${condAnvilUUIDs};`;
}, },
); );

Loading…
Cancel
Save