@@ -40,7 +40,7 @@ function FiltersParser(model, timezone, options) {
40
40
return { [ aggregatorOperator ] : formatedConditions } ;
41
41
} ;
42
42
43
- this . formatCondition = async ( condition ) => {
43
+ this . _ensureIsValidCondition = ( condition ) => {
44
44
if ( _ . isEmpty ( condition ) ) {
45
45
throw new InvalidFiltersFormatError ( 'Empty condition in filter' ) ;
46
46
}
@@ -55,27 +55,35 @@ function FiltersParser(model, timezone, options) {
55
55
|| _ . isUndefined ( condition . value ) ) {
56
56
throw new InvalidFiltersFormatError ( 'Invalid condition format' ) ;
57
57
}
58
+ } ;
58
59
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 ) ;
61
62
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
+ }
65
66
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 ) ;
79
87
}
80
88
81
89
const formatedField = this . formatField ( condition . field ) ;
0 commit comments