fix(striker-ui-api): allow using all or * as condition file/anvil UUIDs

main
Tsu-ba-me 3 years ago
parent 2c4a025cf8
commit 011615e68f
  1. 19
      striker-ui-api/src/lib/request_handlers/anvil/buildQueryAnvilDetail.ts
  2. 19
      striker-ui-api/src/lib/request_handlers/file/buildQueryFileDetail.ts
  3. 4
      striker-ui-api/src/lib/sanitizeQS.ts
  4. 2
      striker-ui-api/src/lib/sanitizeSQLParam.ts

@ -4,20 +4,25 @@ import NODE_AND_DR_RESERVED_MEMORY_SIZE from '../../consts/NODE_AND_DR_RESERVED_
import SERVER_PATHS from '../../consts/SERVER_PATHS'; import SERVER_PATHS from '../../consts/SERVER_PATHS';
import join from '../../join'; import join from '../../join';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
const buildQueryAnvilDetail = ({ const buildQueryAnvilDetail = ({
anvilUUIDs, anvilUUIDs = ['*'],
isForProvisionServer, isForProvisionServer,
}: { }: {
anvilUUIDs?: string[] | '*'; anvilUUIDs?: string[] | '*';
isForProvisionServer?: boolean; isForProvisionServer?: boolean;
}) => { }) => {
const condAnvilsUUID = join(anvilUUIDs, { const condAnvilsUUID = ['all', '*'].includes(anvilUUIDs[0])
beforeReturn: (toReturn) => ? ''
toReturn ? `WHERE anv.anvil_uuid IN (${toReturn})` : '', : join(anvilUUIDs, {
elementWrapper: "'", beforeReturn: (toReturn) =>
separator: ', ', toReturn
}); ? `WHERE anv.anvil_uuid IN (${sanitizeSQLParam(toReturn)})`
: '',
elementWrapper: "'",
separator: ', ',
});
console.log(`condAnvilsUUID=[${condAnvilsUUID}]`); console.log(`condAnvilsUUID=[${condAnvilsUUID}]`);

@ -1,16 +1,21 @@
import join from '../../join'; import join from '../../join';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
const buildQueryFileDetail = ({ const buildQueryFileDetail = ({
fileUUIDs, fileUUIDs = ['*'],
}: { }: {
fileUUIDs?: string[] | '*'; fileUUIDs?: string[] | '*';
}) => { }) => {
const condFileUUIDs = join(fileUUIDs, { const condFileUUIDs = ['all', '*'].includes(fileUUIDs[0])
beforeReturn: (toReturn) => ? ''
toReturn ? `AND fil.file_uuid IN (${toReturn})` : '', : join(fileUUIDs, {
elementWrapper: "'", beforeReturn: (toReturn) =>
separator: ', ', toReturn
}); ? `AND fil.file_uuid IN (${sanitizeSQLParam(toReturn)})`
: '',
elementWrapper: "'",
separator: ', ',
});
console.log(`condFilesUUID=[${condFileUUIDs}]`); console.log(`condFilesUUID=[${condFileUUIDs}]`);

@ -19,10 +19,8 @@ const MAP_TO_RETURN_FUNCTION: MapToReturnFunction = {
: String(qs).split(/[,;]/), : String(qs).split(/[,;]/),
}; };
const sanitizeQS = <ReturnTypeName extends keyof MapToReturnType>( export const sanitizeQS = <ReturnTypeName extends keyof MapToReturnType>(
qs: unknown, qs: unknown,
{ returnType = 'string' }: { returnType?: ReturnTypeName | 'string' } = {}, { returnType = 'string' }: { returnType?: ReturnTypeName | 'string' } = {},
): MapToReturnType[ReturnTypeName] => ): MapToReturnType[ReturnTypeName] =>
MAP_TO_RETURN_FUNCTION[returnType](qs) as MapToReturnType[ReturnTypeName]; MAP_TO_RETURN_FUNCTION[returnType](qs) as MapToReturnType[ReturnTypeName];
export { sanitizeQS };

@ -0,0 +1,2 @@
export const sanitizeSQLParam = (variable: string): string =>
variable.replaceAll(/[']/g, '');
Loading…
Cancel
Save