Skip to content

Commit

Permalink
feat(filters): allow the use of the NotIn operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Molinié committed Aug 2, 2024
1 parent ecc3031 commit 1caaed3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/agent/src/utils/condition-tree-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class ConditionTreeParser {
return 'Number';
}

if (filter.operator === 'In') {
if (filter.operator === 'In' || filter.operator === 'NotIn') {
return [fieldSchema.columnType];
}

Expand Down
7 changes: 4 additions & 3 deletions packages/agent/src/utils/forest-schema/filterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ export default class FrontendFilterableUtils {
Boolean: FrontendFilterableUtils.baseOperators,
Date: FrontendFilterableUtils.dateOperators,
Dateonly: FrontendFilterableUtils.dateOperators,
Enum: [...FrontendFilterableUtils.baseOperators, 'In'],
Number: [...FrontendFilterableUtils.baseOperators, 'In', 'GreaterThan', 'LessThan'],
Enum: [...FrontendFilterableUtils.baseOperators, 'In', 'NotIn'],
Number: [...FrontendFilterableUtils.baseOperators, 'In', 'NotIn', 'GreaterThan', 'LessThan'],
String: [
...FrontendFilterableUtils.baseOperators,
'In',
'NotIn',
'StartsWith',
'EndsWith',
'Contains',
'NotContains',
],
Time: [...FrontendFilterableUtils.baseOperators, 'GreaterThan', 'LessThan'],
Uuid: FrontendFilterableUtils.baseOperators,
Uuid: [...FrontendFilterableUtils.baseOperators, 'In', 'NotIn'],
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export default class EmptyCollectionDecorator extends CollectionDecorator {
valuesByField[field] = valuesByField[field].includes(value) ? [value] : [];
} else if (valuesByField[field] && operator === 'In') {
valuesByField[field] = valuesByField[field].filter(v => (value as unknown[]).includes(v));
} else if (valuesByField[field] && operator === 'NotIn') {
valuesByField[field] = valuesByField[field].filter(v => !(value as unknown[]).includes(v));
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/datasource-mongoose/src/utils/pipeline/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export default class FilterGenerator {
return { $ne: formattedLeafValue };
case 'In':
return { $in: formattedLeafValue };
case 'NotIn':
return { $nin: formattedLeafValue };
case 'IncludesAll':
return { $all: formattedLeafValue };
case 'IncludesNone':
Expand Down

0 comments on commit 1caaed3

Please sign in to comment.