Skip to content

Commit 82fab3d

Browse files
authored
chore(filter): Add a switch statement (#1108)
* Add a switch statement In the filter function a switch statement is added so that it is clear to the reader what happens when the arguments are of various lengths * chore(filter): Add a switch statement * code review suggestions Remove the else block, it should never happen anyway because if it does then the user is misusing the function
1 parent c9fc08c commit 82fab3d

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/query.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,33 @@ class Query {
222222
operatorOrValue?: Operator | AllowedFilterValueType<T>,
223223
value?: AllowedFilterValueType<T>
224224
): Query {
225-
if (isFilter(propertyOrFilter)) {
226-
this.entityFilters.push(propertyOrFilter);
227-
return this;
228-
} else {
225+
if (arguments.length > 1) {
229226
process.emitWarning(
230227
'Providing Filter objects like Composite Filter or Property Filter is recommended when using .filter'
231228
);
232-
let operator = operatorOrValue as Operator;
233-
if (arguments.length === 2) {
234-
value = operatorOrValue as AllowedFilterValueType<T>;
235-
operator = '=';
229+
}
230+
switch (arguments.length) {
231+
case 1: {
232+
if (isFilter(propertyOrFilter)) {
233+
this.entityFilters.push(propertyOrFilter);
234+
}
235+
break;
236+
}
237+
case 2: {
238+
this.filters.push({
239+
name: (propertyOrFilter as String).trim(),
240+
op: '=',
241+
val: operatorOrValue as AllowedFilterValueType<T>,
242+
});
243+
break;
244+
}
245+
case 3: {
246+
this.filters.push({
247+
name: (propertyOrFilter as String).trim(),
248+
op: (operatorOrValue as Operator).trim() as Operator,
249+
val: value,
250+
});
236251
}
237-
238-
this.filters.push({
239-
name: (propertyOrFilter as String).trim(),
240-
op: operator.trim() as Operator,
241-
val: value,
242-
});
243252
}
244253
return this;
245254
}

0 commit comments

Comments
 (0)