fix(striker-ui-api): hoist and enhance join logic

main
Tsu-ba-me 3 years ago
parent 035727b2e0
commit 49fdc9cad4
  1. 15
      striker-ui-api/src/lib/join.ts
  2. 15
      striker-ui-api/src/lib/request_handlers/files/buildQueryFilesDetail.ts
  3. 5
      striker-ui-api/src/types/JoinOptions.d.ts

@ -0,0 +1,15 @@
const join = (
elements: string[] | undefined,
{ beforeReturn, elementWrapper = '', separator = '' }: JoinOptions,
) => {
const joinSeparator = `${elementWrapper}${separator}${elementWrapper}`;
const toReturn =
elements instanceof Array && elements.length > 0
? `${elementWrapper}${elements.join(joinSeparator)}${elementWrapper}`
: undefined;
return typeof beforeReturn === 'function' ? beforeReturn(toReturn) : toReturn;
};
export default join;

@ -1,11 +1,14 @@
const buildQueryFilesDetail = ({ filesUUID }: { filesUUID?: string[] }) => {
let condFilesUUID = '';
import join from '../../join';
if (filesUUID instanceof Array && filesUUID.length > 0) {
const catFilesUUID = `'${filesUUID.join("', '")}'`;
const buildQueryFilesDetail = ({ filesUUID }: { filesUUID?: string[] }) => {
const condFilesUUID = join(filesUUID, {
beforeReturn: (toReturn) =>
toReturn ? `AND fil.file_uuid IN (${toReturn})` : '',
elementWrapper: "'",
separator: ', ',
});
condFilesUUID = `AND fil.file_uuid IN (${catFilesUUID})`;
}
console.log(`condFilesUUID=[${condFilesUUID}]`);
return `
SELECT

@ -0,0 +1,5 @@
type JoinOptions = {
beforeReturn?: (toReturn?: string) => string;
elementWrapper?: string;
separator?: string;
};
Loading…
Cancel
Save