Skip to content

Commit 9d12de2

Browse files
author
Vincent Molinié
committed
feat(filter): add "includes all" filter to array type
1 parent 9d1991a commit 9d12de2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/services/filters-parser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function FiltersParser(modelSchema, timezone, options) {
8181
case 'blank':
8282
case 'equal':
8383
return this.OPERATORS.EQ;
84+
case 'includes_all':
85+
return this.OPERATORS.CONTAINS;
8486
default:
8587
throw new NoMatchingOperatorError();
8688
}
@@ -95,6 +97,7 @@ function FiltersParser(modelSchema, timezone, options) {
9597
case 'equal':
9698
case 'before':
9799
case 'after':
100+
case 'includes_all':
98101
return value;
99102
case 'contains':
100103
case 'not_contains':
@@ -143,6 +146,8 @@ function FiltersParser(modelSchema, timezone, options) {
143146
} : { [this.OPERATORS.EQ]: null };
144147
case 'equal':
145148
return { [this.OPERATORS.EQ]: value };
149+
case 'includes_all':
150+
return { [this.OPERATORS.CONTAINS]: value };
146151
default:
147152
throw new NoMatchingOperatorError();
148153
}

src/utils/operators.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function Operators(options) {
66
if (options && options.Sequelize && options.Sequelize.Op) {
77
const { Op } = options.Sequelize;
88
this.AND = Op.and;
9+
this.CONTAINS = Op.contains;
910
this.EQ = Op.eq;
1011
this.GT = Op.gt;
1112
this.GTE = Op.gte;
@@ -19,6 +20,7 @@ function Operators(options) {
1920
this.OR = Op.or;
2021
} else {
2122
this.AND = '$and';
23+
this.CONTAINS = '$contains';
2224
this.EQ = '$eq';
2325
this.GT = '$gt';
2426
this.GTE = '$gte';

test/services/filters-parser.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ describe('services > filters-parser', () => {
120120
expect(defaultFiltersParser.formatOperatorValue.bind('random', value)).toThrow(NoMatchingOperatorError);
121121
});
122122
});
123+
124+
it('should return the appropriate value (array)', () => {
125+
expect.assertions(1);
126+
127+
expect(defaultFiltersParser.formatOperatorValue('includes_all', [1, 2])).toStrictEqual({ [OPERATORS.CONTAINS]: [1, 2] });
128+
});
123129
});
124130

125131
describe('formatAggregatorOperator function', () => {

0 commit comments

Comments
 (0)