forked from primeroIMS/primero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-operator.js
45 lines (43 loc) · 1.2 KB
/
build-operator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
import { COMPARISON_OPERATORS, LOGICAL_OPERATORS, MATHEMATICAL_OPERATORS } from "../constants";
import {
eqOperator,
geOperator,
gtOperator,
leOperator,
ltOperator,
inOperator,
andOperator,
orOperator,
notOperator,
sumOperator,
avgOperator
} from "../operators";
export default (operator, value, extra) => {
switch (operator) {
case COMPARISON_OPERATORS.EQ:
return eqOperator(value);
case COMPARISON_OPERATORS.GE:
return geOperator(value);
case COMPARISON_OPERATORS.GT:
return gtOperator(value);
case COMPARISON_OPERATORS.LE:
return leOperator(value);
case COMPARISON_OPERATORS.LT:
return ltOperator(value);
case COMPARISON_OPERATORS.IN:
return inOperator(value);
case LOGICAL_OPERATORS.AND:
return andOperator(value);
case LOGICAL_OPERATORS.OR:
return orOperator(value);
case LOGICAL_OPERATORS.NOT:
return notOperator(value);
case MATHEMATICAL_OPERATORS.SUM:
return sumOperator(value);
case MATHEMATICAL_OPERATORS.AVG:
return avgOperator(value, extra);
default:
throw Error(`Operator ${operator} is not valid.`);
}
};