Skip to content

Commit c670b2b

Browse files
committed
refactor: simplify ternary operator
Concat multiple operators with 'and'
1 parent 7fca3a5 commit c670b2b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/generator/01-base/static/queriesWithQueryLanguage.ts.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ const flattenWhere = (
302302
return entries;
303303
};
304304

305-
const evaluateCaseExpression = (exp: QueryFilter<any>, nestedPaths: string[]): string =>
306-
`(${flattenWhere(exp.IF as QueryFilter<any>, nestedPaths)} ? ${flattenWhere(exp.THEN as QueryFilter<any>, nestedPaths)} : ${flattenWhere(exp.ELSE as QueryFilter<any>, nestedPaths)})`;
305+
const evaluateCaseExpression = (exp: QueryFilter<any>, nestedPaths: string[]): string => {
306+
const ifExp = flattenWhere(exp.IF as QueryFilter<any>, nestedPaths).join(' and ');
307+
const thenBranch = flattenWhere(exp.THEN as QueryFilter<any>, nestedPaths).join(' and ');
308+
const elseBranch = flattenWhere(exp.ELSE as QueryFilter<any>, nestedPaths).join(' and ');
309+
return `(${ifExp} ? ${thenBranch} : ${elseBranch})`;
310+
};
307311

308312
const assembleOrderBy = (orderBy: OrderBy<any>[] = []): Record<string, string> => {
309313
if(!orderBy.length) {

0 commit comments

Comments
 (0)