Skip to content

Commit d957bb5

Browse files
feat(filter): add "is in" filter (#666)
1 parent 9b71390 commit d957bb5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/services/filters-parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ function FiltersParser(model, timezone, options) {
173173
case 'equal':
174174
return parseFct(value);
175175
case 'in':
176-
return { $in: parseFct(value) };
176+
return (Array.isArray(value))
177+
? { $in: parseFct(value) }
178+
: { $in: value.split(',').map((elem) => elem.trim()) };
177179
default:
178180
throw new NoMatchingOperatorError();
179181
}

test/tests/services/filters-parser.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ describe('service > filters-parser', () => {
127127

128128
describe('formatCondition function', () => {
129129
it('should format conditions correctly', async () => {
130-
expect.assertions(3);
130+
expect.assertions(4);
131131
expect(await defaultParser.formatCondition({ field: 'name', operator: 'starts_with', value: 'P' })).toStrictEqual({ name: new RegExp('^P.*') });
132132
expect(await defaultParser.formatCondition({ field: 'isBig', operator: 'equal', value: 'true' })).toStrictEqual({ isBig: true });
133133
expect(await defaultParser.formatCondition({ field: 'size', operator: 'greater_than', value: '56' })).toStrictEqual({ size: { $gt: 56 } });
134+
expect(await defaultParser.formatCondition({ field: 'name', operator: 'in', value: 'Pyk, Dragonstone ' })).toStrictEqual({ name: { $in: ['Pyk', 'Dragonstone'] } });
134135
});
135136

136137
describe('on empty condition', () => {

0 commit comments

Comments
 (0)