Skip to content

Commit b636536

Browse files
author
Vincent Molinié
committed
chore: fix CC issue
1 parent 090a902 commit b636536

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/services/filters-parser.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function FiltersParser(model, timezone, options) {
4040
return { [aggregatorOperator]: formatedConditions };
4141
};
4242

43-
this.formatCondition = async (condition) => {
43+
this._ensureIsValidCondition = (condition) => {
4444
if (_.isEmpty(condition)) {
4545
throw new InvalidFiltersFormatError('Empty condition in filter');
4646
}
@@ -55,27 +55,35 @@ function FiltersParser(model, timezone, options) {
5555
|| _.isUndefined(condition.value)) {
5656
throw new InvalidFiltersFormatError('Invalid condition format');
5757
}
58+
};
5859

59-
if (this.isSmartField(modelSchema, condition.field)) {
60-
const fieldFound = modelSchema.fields.find((field) => field.field === condition.field);
60+
this.getSmartFieldCondition = async (condition) => {
61+
const fieldFound = modelSchema.fields.find((field) => field.field === condition.field);
6162

62-
if (!fieldFound.filter) {
63-
throw new Error(`"filter" method missing on smart field "${fieldFound.field}"`);
64-
}
63+
if (!fieldFound.filter) {
64+
throw new Error(`"filter" method missing on smart field "${fieldFound.field}"`);
65+
}
6566

66-
const formattedCondition = fieldFound
67-
.filter({
68-
where: await this.formatOperatorValue(
69-
condition.field,
70-
condition.operator,
71-
condition.value,
72-
),
73-
condition,
74-
});
75-
if (!formattedCondition) {
76-
throw new Error(`"filter" method on smart field "${fieldFound.field}" must return a condition`);
77-
}
78-
return formattedCondition;
67+
const formattedCondition = fieldFound
68+
.filter({
69+
where: await this.formatOperatorValue(
70+
condition.field,
71+
condition.operator,
72+
condition.value,
73+
),
74+
condition,
75+
});
76+
if (!formattedCondition) {
77+
throw new Error(`"filter" method on smart field "${fieldFound.field}" must return a condition`);
78+
}
79+
return formattedCondition;
80+
};
81+
82+
this.formatCondition = async (condition) => {
83+
this._ensureIsValidCondition(condition);
84+
85+
if (this.isSmartField(modelSchema, condition.field)) {
86+
return this.getSmartFieldCondition(condition);
7987
}
8088

8189
const formatedField = this.formatField(condition.field);

0 commit comments

Comments
 (0)