Skip to content

Commit

Permalink
1-3128: handle nulls in query
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Nov 18, 2024
1 parent dc8ff5c commit 01eb8c3
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/lib/features/feature-search/search-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,38 @@ export const applyGenericQueryParams = (
): void => {
queryParams.forEach((param) => {
const isSingleParam = param.values.length === 1;
const containsNulls = param.values.includes(null);
switch (param.operator) {
case 'IS':
case 'IS_ANY_OF':
query.whereIn(param.field, param.values);
if (isSingleParam) {
query.where(param.field, param.values[0]);
} else {
if (containsNulls) {
query.where((qb) =>
qb
.whereIn(param.field, param.values)
.orWhereNull(param.field),
);
} else {
query.whereIn(param.field, param.values);
}
}
break;
case 'IS_NOT':
case 'IS_NONE_OF':
if (isSingleParam) {
query.whereNot(param.field, param.values[0]);
} else {
query.whereNotIn(param.field, param.values);
if (containsNulls) {
query.where((qb) =>
qb
.whereNotIn(param.field, param.values)
.orWhereNotNull(param.field),
);
} else {
query.whereNotIn(param.field, param.values);
}
}
break;
case 'IS_BEFORE':
Expand Down

0 comments on commit 01eb8c3

Please sign in to comment.