@zeniai/client-epic-state 5.0.82-betaAR3 → 5.0.82-betaAR5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,16 +7,20 @@ function detectRuleOverlap({ candidateCriteria, existingRules, excludeRuleId, })
|
|
|
7
7
|
const candidateDepartment = pickDepartment(candidateCriteria);
|
|
8
8
|
const overlaps = [];
|
|
9
9
|
for (const rule of existingRules) {
|
|
10
|
-
if (rule.approvalRuleId === excludeRuleId)
|
|
10
|
+
if (rule.approvalRuleId === excludeRuleId) {
|
|
11
11
|
continue;
|
|
12
|
-
|
|
12
|
+
}
|
|
13
|
+
if (rule.isFallback === true) {
|
|
13
14
|
continue;
|
|
15
|
+
}
|
|
14
16
|
const ruleVendor = pickVendor(rule.criteria);
|
|
15
17
|
const ruleDepartment = pickDepartment(rule.criteria);
|
|
16
|
-
if (!areVendorCriteriaEqual(candidateVendor, ruleVendor))
|
|
18
|
+
if (!areVendorCriteriaEqual(candidateVendor, ruleVendor)) {
|
|
17
19
|
continue;
|
|
18
|
-
|
|
20
|
+
}
|
|
21
|
+
if (!areDepartmentCriteriaEqual(candidateDepartment, ruleDepartment)) {
|
|
19
22
|
continue;
|
|
23
|
+
}
|
|
20
24
|
const ruleAmount = pickAmount(rule.criteria);
|
|
21
25
|
if (amountsOverlap(candidateAmount, ruleAmount)) {
|
|
22
26
|
overlaps.push({ conflictingRule: rule });
|
|
@@ -28,26 +32,33 @@ const pickAmount = (criteria) => criteria.find((c) => c.type === 'amount');
|
|
|
28
32
|
const pickVendor = (criteria) => criteria.find((c) => c.type === 'vendor');
|
|
29
33
|
const pickDepartment = (criteria) => criteria.find((c) => c.type === 'department');
|
|
30
34
|
const areVendorCriteriaEqual = (a, b) => {
|
|
31
|
-
if (a == null && b == null)
|
|
35
|
+
if (a == null && b == null) {
|
|
32
36
|
return true;
|
|
33
|
-
|
|
37
|
+
}
|
|
38
|
+
if (a == null || b == null) {
|
|
34
39
|
return false;
|
|
35
|
-
|
|
40
|
+
}
|
|
41
|
+
if (a.operator !== b.operator) {
|
|
36
42
|
return false;
|
|
43
|
+
}
|
|
37
44
|
return idsEqual(a.vendorIds, b.vendorIds);
|
|
38
45
|
};
|
|
39
46
|
const areDepartmentCriteriaEqual = (a, b) => {
|
|
40
|
-
if (a == null && b == null)
|
|
47
|
+
if (a == null && b == null) {
|
|
41
48
|
return true;
|
|
42
|
-
|
|
49
|
+
}
|
|
50
|
+
if (a == null || b == null) {
|
|
43
51
|
return false;
|
|
44
|
-
|
|
52
|
+
}
|
|
53
|
+
if (a.operator !== b.operator) {
|
|
45
54
|
return false;
|
|
55
|
+
}
|
|
46
56
|
return idsEqual(a.departmentIds, b.departmentIds);
|
|
47
57
|
};
|
|
48
58
|
const idsEqual = (a, b) => {
|
|
49
|
-
if (a.length !== b.length)
|
|
59
|
+
if (a.length !== b.length) {
|
|
50
60
|
return false;
|
|
61
|
+
}
|
|
51
62
|
const aSorted = [...a].sort();
|
|
52
63
|
const bSorted = [...b].sort();
|
|
53
64
|
return aSorted.every((id, i) => id === bSorted[i]);
|
|
@@ -55,8 +66,9 @@ const idsEqual = (a, b) => {
|
|
|
55
66
|
const amountsOverlap = (a, b) => {
|
|
56
67
|
// Absent amount criteria covers the whole real line, so any
|
|
57
68
|
// pairing involving an absent one is a guaranteed overlap.
|
|
58
|
-
if (a == null || b == null)
|
|
69
|
+
if (a == null || b == null) {
|
|
59
70
|
return true;
|
|
71
|
+
}
|
|
60
72
|
const aLow = a.min?.amount ?? Number.NEGATIVE_INFINITY;
|
|
61
73
|
const aHigh = a.max?.amount ?? Number.POSITIVE_INFINITY;
|
|
62
74
|
const bLow = b.min?.amount ?? Number.NEGATIVE_INFINITY;
|
|
@@ -4,16 +4,20 @@ export function detectRuleOverlap({ candidateCriteria, existingRules, excludeRul
|
|
|
4
4
|
const candidateDepartment = pickDepartment(candidateCriteria);
|
|
5
5
|
const overlaps = [];
|
|
6
6
|
for (const rule of existingRules) {
|
|
7
|
-
if (rule.approvalRuleId === excludeRuleId)
|
|
7
|
+
if (rule.approvalRuleId === excludeRuleId) {
|
|
8
8
|
continue;
|
|
9
|
-
|
|
9
|
+
}
|
|
10
|
+
if (rule.isFallback === true) {
|
|
10
11
|
continue;
|
|
12
|
+
}
|
|
11
13
|
const ruleVendor = pickVendor(rule.criteria);
|
|
12
14
|
const ruleDepartment = pickDepartment(rule.criteria);
|
|
13
|
-
if (!areVendorCriteriaEqual(candidateVendor, ruleVendor))
|
|
15
|
+
if (!areVendorCriteriaEqual(candidateVendor, ruleVendor)) {
|
|
14
16
|
continue;
|
|
15
|
-
|
|
17
|
+
}
|
|
18
|
+
if (!areDepartmentCriteriaEqual(candidateDepartment, ruleDepartment)) {
|
|
16
19
|
continue;
|
|
20
|
+
}
|
|
17
21
|
const ruleAmount = pickAmount(rule.criteria);
|
|
18
22
|
if (amountsOverlap(candidateAmount, ruleAmount)) {
|
|
19
23
|
overlaps.push({ conflictingRule: rule });
|
|
@@ -25,26 +29,33 @@ const pickAmount = (criteria) => criteria.find((c) => c.type === 'amount');
|
|
|
25
29
|
const pickVendor = (criteria) => criteria.find((c) => c.type === 'vendor');
|
|
26
30
|
const pickDepartment = (criteria) => criteria.find((c) => c.type === 'department');
|
|
27
31
|
const areVendorCriteriaEqual = (a, b) => {
|
|
28
|
-
if (a == null && b == null)
|
|
32
|
+
if (a == null && b == null) {
|
|
29
33
|
return true;
|
|
30
|
-
|
|
34
|
+
}
|
|
35
|
+
if (a == null || b == null) {
|
|
31
36
|
return false;
|
|
32
|
-
|
|
37
|
+
}
|
|
38
|
+
if (a.operator !== b.operator) {
|
|
33
39
|
return false;
|
|
40
|
+
}
|
|
34
41
|
return idsEqual(a.vendorIds, b.vendorIds);
|
|
35
42
|
};
|
|
36
43
|
const areDepartmentCriteriaEqual = (a, b) => {
|
|
37
|
-
if (a == null && b == null)
|
|
44
|
+
if (a == null && b == null) {
|
|
38
45
|
return true;
|
|
39
|
-
|
|
46
|
+
}
|
|
47
|
+
if (a == null || b == null) {
|
|
40
48
|
return false;
|
|
41
|
-
|
|
49
|
+
}
|
|
50
|
+
if (a.operator !== b.operator) {
|
|
42
51
|
return false;
|
|
52
|
+
}
|
|
43
53
|
return idsEqual(a.departmentIds, b.departmentIds);
|
|
44
54
|
};
|
|
45
55
|
const idsEqual = (a, b) => {
|
|
46
|
-
if (a.length !== b.length)
|
|
56
|
+
if (a.length !== b.length) {
|
|
47
57
|
return false;
|
|
58
|
+
}
|
|
48
59
|
const aSorted = [...a].sort();
|
|
49
60
|
const bSorted = [...b].sort();
|
|
50
61
|
return aSorted.every((id, i) => id === bSorted[i]);
|
|
@@ -52,8 +63,9 @@ const idsEqual = (a, b) => {
|
|
|
52
63
|
const amountsOverlap = (a, b) => {
|
|
53
64
|
// Absent amount criteria covers the whole real line, so any
|
|
54
65
|
// pairing involving an absent one is a guaranteed overlap.
|
|
55
|
-
if (a == null || b == null)
|
|
66
|
+
if (a == null || b == null) {
|
|
56
67
|
return true;
|
|
68
|
+
}
|
|
57
69
|
const aLow = a.min?.amount ?? Number.NEGATIVE_INFINITY;
|
|
58
70
|
const aHigh = a.max?.amount ?? Number.POSITIVE_INFINITY;
|
|
59
71
|
const bLow = b.min?.amount ?? Number.NEGATIVE_INFINITY;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.82-
|
|
3
|
+
"version": "5.0.82-betaAR5",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|