@outliant/sunrise-utils 1.0.0 → 1.0.3
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.
- package/CHANGELOG.md +22 -0
- package/README.md +20 -3
- package/helpers/projectFilter/criticalPathFilter.js +116 -0
- package/helpers/projectFilter/index.js +27 -0
- package/helpers/projectFilter/isGeneratedFilter.js +41 -0
- package/helpers/projectFilter/onHoldFilter.js +41 -0
- package/helpers/projectFilter/regionFilter.js +56 -0
- package/helpers/projectFilter/tagFilter.js +81 -0
- package/helpers/searchFilter.js +3 -3
- package/index.js +3 -1
- package/lib/fieldConditions.js +4 -12
- package/lib/projectPipeline.js +105 -0
- package/lib/taskPipeline.js +13 -13
- package/package.json +1 -4
- /package/helpers/{taskSortScript.js → sortScript.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,30 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [1.0.3](https://github.com/outliant/sunrise-utils/compare/1.0.2...1.0.3)
|
|
8
|
+
|
|
9
|
+
- chore: project pipeline filter query and sorting script #860pt9g1t [`533484f`](https://github.com/outliant/sunrise-utils/commit/533484fc97909d2ba45d425db57bc5942109c6f0)
|
|
10
|
+
- chore: updated README [`62743ce`](https://github.com/outliant/sunrise-utils/commit/62743ce921655c3c1b64395268d3c1acf624071f)
|
|
11
|
+
|
|
12
|
+
#### [1.0.2](https://github.com/outliant/sunrise-utils/compare/1.0.1...1.0.2)
|
|
13
|
+
|
|
14
|
+
> 23 February 2023
|
|
15
|
+
|
|
16
|
+
- chore(release): 1.0.2 [`499f9e5`](https://github.com/outliant/sunrise-utils/commit/499f9e5c633f6b85e413ff57905c46aba6adc16a)
|
|
17
|
+
- chore: updated readme file [`97a2c96`](https://github.com/outliant/sunrise-utils/commit/97a2c96f3e88e7652bff68623e5ffb17e12db000)
|
|
18
|
+
- chore: changed to private [`fa55dc4`](https://github.com/outliant/sunrise-utils/commit/fa55dc461a6fd9da40536e37a087f3832d78ba33)
|
|
19
|
+
|
|
20
|
+
#### [1.0.1](https://github.com/outliant/sunrise-utils/compare/1.0.0...1.0.1)
|
|
21
|
+
|
|
22
|
+
> 23 February 2023
|
|
23
|
+
|
|
24
|
+
- chore(release): 1.0.1 [`c8a85ed`](https://github.com/outliant/sunrise-utils/commit/c8a85ed406be1d6475829ea0905478687c71278e)
|
|
25
|
+
- chore: changed to private [`0f79a6b`](https://github.com/outliant/sunrise-utils/commit/0f79a6b4ebd9101d0d9ce523e23c3268a68a0bf1)
|
|
26
|
+
|
|
7
27
|
#### 1.0.0
|
|
8
28
|
|
|
29
|
+
> 23 February 2023
|
|
30
|
+
|
|
9
31
|
- chore: task pipeline fixes #860pt9g1t [`#860`](https://github.com/outliant/sunrise-utils/issues/860)
|
|
10
32
|
- chore: initial setup [`4e2206c`](https://github.com/outliant/sunrise-utils/commit/4e2206c5a002629fca7b608ed9cf6c60f3e6be37)
|
|
11
33
|
- chore: task pipeline filter query and sorting script #860pt9g1t [`3bae8e1`](https://github.com/outliant/sunrise-utils/commit/3bae8e1aa6e02e6734ebaa6cdb3d822a7992aa21)
|
package/README.md
CHANGED
|
@@ -6,11 +6,28 @@ You have the following utils available:
|
|
|
6
6
|
|
|
7
7
|
- `log`: Custom logging for sunrise projects
|
|
8
8
|
- `fieldConditions`: Returns an array for sunrise column filters
|
|
9
|
-
- `taskPipeline`:
|
|
9
|
+
- `taskPipeline`: Task pipeline reusable codes
|
|
10
10
|
- `taskStatusOptions`: Array of task status column options
|
|
11
11
|
- `defaultCustomColumns`: Array of task pipeline custom columns
|
|
12
|
-
- `buildFiltersQuery()`: Function to build task pipeline filter ES query
|
|
13
|
-
|
|
12
|
+
- `buildFiltersQuery(orgId, departmentId, filters = [], query = {}, searchFields = [])`: Function to build task pipeline filter ES query
|
|
13
|
+
- `orgId`: Organization ID
|
|
14
|
+
- `departmentId`: Department ID
|
|
15
|
+
- `filters`: Array of filters
|
|
16
|
+
- `query`: Query request params that includes `size`, `projectId`, `search`
|
|
17
|
+
- `searchFields`: Array of fields that the `search` will run against including the defaults
|
|
18
|
+
- `buildSortScript(query = {}, customSort = [])`: Function to build task pipeline sort script
|
|
19
|
+
- `query`: Query request params that includes `sort`, `sortBy`
|
|
20
|
+
- `customSort`: Array of custom ES sorting script that will be appended to the list of sorting script
|
|
21
|
+
- `projectPipeline`: Project pipeline reusable codes
|
|
22
|
+
- `buildFiltersQuery(orgId, departmentId, filters = [], query = {}, searchFields = [])`: Function to build task pipeline filter ES query
|
|
23
|
+
- `orgId`: Organization ID
|
|
24
|
+
- `departmentId`: Department ID
|
|
25
|
+
- `filters`: Array of filters
|
|
26
|
+
- `query`: Query request params that includes `size`, `projectId`, `search`
|
|
27
|
+
- `searchFields`: Array of fields that the `search` will run against including the defaults
|
|
28
|
+
- `buildSortScript(query = {}, customSort = [])`: Function to build task pipeline sort script
|
|
29
|
+
- `query`: Query request params that includes `sort`, `sortBy`
|
|
30
|
+
- `customSort`: Array of custom ES sorting script that will be appended to the list of sorting script
|
|
14
31
|
|
|
15
32
|
## Installation
|
|
16
33
|
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
module.exports = (filter) => {
|
|
2
|
+
switch (filter.condition) {
|
|
3
|
+
case 'is_equal':
|
|
4
|
+
return module.exports.isEqual(filter);
|
|
5
|
+
case 'contains_any':
|
|
6
|
+
return module.exports.containsAny(filter);
|
|
7
|
+
case 'contains_none':
|
|
8
|
+
case 'not_equal':
|
|
9
|
+
return module.exports.containsNone(filter);
|
|
10
|
+
case 'greater_than_or_equal':
|
|
11
|
+
return module.exports.greaterThanOrEqual(filter);
|
|
12
|
+
case 'less_than_or_equal':
|
|
13
|
+
return module.exports.lessThanOrEqual(filter);
|
|
14
|
+
|
|
15
|
+
default:
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports.isEqual = (filter) => {
|
|
21
|
+
let value = filter.value;
|
|
22
|
+
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
value = value.split(',');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
bool: {
|
|
29
|
+
must: value.map((x) => {
|
|
30
|
+
return {
|
|
31
|
+
term: {
|
|
32
|
+
'critical_path.stage_id': {
|
|
33
|
+
value: x
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports.containsAny = (filter) => {
|
|
43
|
+
let value = filter.value;
|
|
44
|
+
|
|
45
|
+
if (typeof value === 'string') {
|
|
46
|
+
value = value.split(',');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
bool: {
|
|
51
|
+
should: value.map((x) => {
|
|
52
|
+
return {
|
|
53
|
+
term: {
|
|
54
|
+
'critical_path.stage_id': {
|
|
55
|
+
value: x
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
module.exports.containsNone = (filter) => {
|
|
65
|
+
let value = filter.value;
|
|
66
|
+
|
|
67
|
+
if (typeof value === 'string') {
|
|
68
|
+
value = value.split(',');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
bool: {
|
|
73
|
+
must_not: value.map((x) => {
|
|
74
|
+
return {
|
|
75
|
+
term: {
|
|
76
|
+
'critical_path.stage_id': {
|
|
77
|
+
value: x
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
module.exports.greaterThanOrEqual = (filter) => {
|
|
87
|
+
let value = filter.value;
|
|
88
|
+
|
|
89
|
+
if (typeof value === 'string') {
|
|
90
|
+
value = parseInt(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
range: {
|
|
95
|
+
'critical_path.stage_index': {
|
|
96
|
+
gte: value
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
module.exports.lessThanOrEqual = (filter) => {
|
|
103
|
+
let value = filter.value;
|
|
104
|
+
|
|
105
|
+
if (typeof value === 'string') {
|
|
106
|
+
value = parseInt(value);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
range: {
|
|
111
|
+
'critical_path.stage_index': {
|
|
112
|
+
lte: value
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const buildRegionFilter = require('./regionFilter');
|
|
2
|
+
const buildCriticalPathFilter = require('./criticalPathFilter');
|
|
3
|
+
const buildOnHoldFilter = require('./onHoldFilter');
|
|
4
|
+
const buildIsGeneratedFilter = require('./isGeneratedFilter');
|
|
5
|
+
const buildTagFilter = require('./tagFilter');
|
|
6
|
+
const buildProjectFieldFilter = require('./projectFieldFilter');
|
|
7
|
+
|
|
8
|
+
module.exports.buildProjectPipelineFilter = (filter) => {
|
|
9
|
+
switch (filter.type) {
|
|
10
|
+
case 'tags':
|
|
11
|
+
return buildTagFilter(filter);
|
|
12
|
+
case 'region':
|
|
13
|
+
return buildRegionFilter(filter);
|
|
14
|
+
case 'criticalPathStage':
|
|
15
|
+
return buildCriticalPathFilter(filter);
|
|
16
|
+
case 'on_hold':
|
|
17
|
+
return buildOnHoldFilter(filter);
|
|
18
|
+
case 'is_generated':
|
|
19
|
+
return buildIsGeneratedFilter(filter);
|
|
20
|
+
case 'dealPropertyMappings':
|
|
21
|
+
case 'ticketPropertyMappings':
|
|
22
|
+
case 'contactPropertyMappings':
|
|
23
|
+
return buildProjectFieldFilter(filter);
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = (filter) => {
|
|
2
|
+
switch (filter.condition) {
|
|
3
|
+
case 'is_equal':
|
|
4
|
+
return module.exports.isEqual();
|
|
5
|
+
case 'not_equal':
|
|
6
|
+
return module.exports.isNotEqual();
|
|
7
|
+
default:
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.isEqual = () => {
|
|
13
|
+
return {
|
|
14
|
+
match: {
|
|
15
|
+
is_generated: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports.isNotEqual = () => {
|
|
21
|
+
return {
|
|
22
|
+
bool: {
|
|
23
|
+
should: [
|
|
24
|
+
{
|
|
25
|
+
match: {
|
|
26
|
+
is_generated: false
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
bool: {
|
|
31
|
+
must_not: {
|
|
32
|
+
exists: {
|
|
33
|
+
field: 'is_generated'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module.exports = (filter) => {
|
|
2
|
+
switch (filter.condition) {
|
|
3
|
+
case 'is_equal':
|
|
4
|
+
return module.exports.isEqual();
|
|
5
|
+
case 'not_equal':
|
|
6
|
+
return module.exports.isNotEqual();
|
|
7
|
+
default:
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports.isEqual = (filter) => {
|
|
13
|
+
return {
|
|
14
|
+
match: {
|
|
15
|
+
on_hold: true
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports.isNotEqual = (filter) => {
|
|
21
|
+
return {
|
|
22
|
+
bool: {
|
|
23
|
+
should: [
|
|
24
|
+
{
|
|
25
|
+
match: {
|
|
26
|
+
on_hold: false
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
bool: {
|
|
31
|
+
must_not: {
|
|
32
|
+
exists: {
|
|
33
|
+
field: 'on_hold'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module.exports = (filter) => {
|
|
2
|
+
switch (filter.condition) {
|
|
3
|
+
case 'contains_any':
|
|
4
|
+
case 'is_equal':
|
|
5
|
+
return module.exports.containsAny(filter);
|
|
6
|
+
case 'contains_none':
|
|
7
|
+
case 'not_equal':
|
|
8
|
+
return module.exports.containsNone(filter);
|
|
9
|
+
default:
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports.containsAny = (filter) => {
|
|
15
|
+
let value = filter.value;
|
|
16
|
+
|
|
17
|
+
if (typeof value === 'string') {
|
|
18
|
+
value = value.split(',');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
bool: {
|
|
23
|
+
should: value.map((x) => {
|
|
24
|
+
return {
|
|
25
|
+
term: {
|
|
26
|
+
region_id: {
|
|
27
|
+
value: x
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports.containsNone = (filter) => {
|
|
37
|
+
let value = filter.value;
|
|
38
|
+
|
|
39
|
+
if (typeof value === 'string') {
|
|
40
|
+
value = value.split(',');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
bool: {
|
|
45
|
+
must_not: value.map((x) => {
|
|
46
|
+
return {
|
|
47
|
+
term: {
|
|
48
|
+
region_id: {
|
|
49
|
+
value: x
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module.exports = (filter) => {
|
|
2
|
+
switch (filter.condition) {
|
|
3
|
+
case 'contains_any':
|
|
4
|
+
return module.exports.containsAny(filter);
|
|
5
|
+
case 'contains_none':
|
|
6
|
+
case 'not_equal':
|
|
7
|
+
return module.exports.containsNone(filter);
|
|
8
|
+
case 'contains_all':
|
|
9
|
+
case 'is_equal':
|
|
10
|
+
case 'contains':
|
|
11
|
+
return module.exports.containsAll(filter);
|
|
12
|
+
default:
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports.containsAny = (filter) => {
|
|
18
|
+
let value = filter.value;
|
|
19
|
+
|
|
20
|
+
if (typeof value === 'string') {
|
|
21
|
+
value = value.split(',');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
bool: {
|
|
26
|
+
should: value.map((x) => {
|
|
27
|
+
return {
|
|
28
|
+
term: {
|
|
29
|
+
tag_ids: {
|
|
30
|
+
value: x
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
module.exports.containsNone = (filter) => {
|
|
40
|
+
let value = filter.value;
|
|
41
|
+
|
|
42
|
+
if (typeof value === 'string') {
|
|
43
|
+
value = value.split(',');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
bool: {
|
|
48
|
+
must_not: value.map((x) => {
|
|
49
|
+
return {
|
|
50
|
+
term: {
|
|
51
|
+
tag_ids: {
|
|
52
|
+
value: x
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports.containsAll = (filter) => {
|
|
62
|
+
let value = filter.value;
|
|
63
|
+
|
|
64
|
+
if (typeof value === 'string') {
|
|
65
|
+
value = value.split(',');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
bool: {
|
|
70
|
+
must: value.map((x) => {
|
|
71
|
+
return {
|
|
72
|
+
term: {
|
|
73
|
+
tag_ids: {
|
|
74
|
+
value: x
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
package/helpers/searchFilter.js
CHANGED
|
@@ -38,9 +38,9 @@ module.exports = (query = {}, searchFields = []) => {
|
|
|
38
38
|
});
|
|
39
39
|
} else {
|
|
40
40
|
should.push({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
multi_match: {
|
|
42
|
+
query: parsedQuery,
|
|
43
|
+
fields: localFields.map((x) => `${x}^5`)
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const log = require('./lib/logger');
|
|
2
2
|
const fieldConditions = require('./lib/fieldConditions');
|
|
3
3
|
const taskPipeline = require('./lib/taskPipeline');
|
|
4
|
+
const projectPipeline = require('./lib/projectPipeline');
|
|
4
5
|
|
|
5
6
|
module.exports = {
|
|
6
7
|
log,
|
|
7
8
|
fieldConditions,
|
|
8
|
-
taskPipeline
|
|
9
|
+
taskPipeline,
|
|
10
|
+
projectPipeline
|
|
9
11
|
};
|
package/lib/fieldConditions.js
CHANGED
|
@@ -17,12 +17,8 @@ module.exports.conditions = {
|
|
|
17
17
|
value: 'is_not_empty'
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
label: '
|
|
21
|
-
value: '
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
label: 'Contains None',
|
|
25
|
-
value: 'contains_none'
|
|
20
|
+
label: 'Is any of',
|
|
21
|
+
value: 'is_any_of'
|
|
26
22
|
}
|
|
27
23
|
],
|
|
28
24
|
textarea: [
|
|
@@ -43,12 +39,8 @@ module.exports.conditions = {
|
|
|
43
39
|
value: 'is_not_empty'
|
|
44
40
|
},
|
|
45
41
|
{
|
|
46
|
-
label: '
|
|
47
|
-
value: '
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
label: 'Contains None',
|
|
51
|
-
value: 'contains_none'
|
|
42
|
+
label: 'Is any of',
|
|
43
|
+
value: 'is_any_of'
|
|
52
44
|
}
|
|
53
45
|
],
|
|
54
46
|
number: [
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const { validate: isUuid } = require('uuid');
|
|
2
|
+
const { buildProjectPipelineFilter } = require('../helpers/projectFilter');
|
|
3
|
+
const searchFilter = require('../helpers/searchFilter');
|
|
4
|
+
const sortScript = require('../helpers/sortScript');
|
|
5
|
+
|
|
6
|
+
class ProjectPipeline {
|
|
7
|
+
buildFiltersQuery(
|
|
8
|
+
orgId,
|
|
9
|
+
departmentId,
|
|
10
|
+
filters = [],
|
|
11
|
+
query = {},
|
|
12
|
+
searchFields = []
|
|
13
|
+
) {
|
|
14
|
+
const mustQuery = [
|
|
15
|
+
{
|
|
16
|
+
term: {
|
|
17
|
+
organization_id: {
|
|
18
|
+
value: orgId
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
term: {
|
|
24
|
+
department_id: {
|
|
25
|
+
value: departmentId
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
if (query.search && query.search.length > 0) {
|
|
32
|
+
const should = searchFilter(query, searchFields);
|
|
33
|
+
|
|
34
|
+
if (should.length > 0) {
|
|
35
|
+
mustQuery.push({
|
|
36
|
+
bool: {
|
|
37
|
+
should
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!filters.length) {
|
|
44
|
+
return {
|
|
45
|
+
bool: {
|
|
46
|
+
must: mustQuery
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const filter of filters) {
|
|
52
|
+
const queryFilter = buildProjectPipelineFilter(filter);
|
|
53
|
+
|
|
54
|
+
if (queryFilter) {
|
|
55
|
+
mustQuery.push(queryFilter);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return { bool: { must: mustQuery } };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
buildSortScript(query = {}, customSort = []) {
|
|
63
|
+
const sort = query.sort || 'desc';
|
|
64
|
+
const sortBy = query.sortBy || 'created_at';
|
|
65
|
+
const sortByMultiple = sortBy.split(',');
|
|
66
|
+
const projectPipelinesSort = [];
|
|
67
|
+
|
|
68
|
+
if (sortByMultiple.length > 0) {
|
|
69
|
+
sortByMultiple.forEach((s) => {
|
|
70
|
+
if (isUuid(s)) {
|
|
71
|
+
projectPipelinesSort.push(sortScript.projectFieldNumeric(sort, s));
|
|
72
|
+
projectPipelinesSort.push(sortScript.projectFieldText(sort, s));
|
|
73
|
+
} else if (s === 'region') {
|
|
74
|
+
projectPipelinesSort.push(sortScript.region(sort));
|
|
75
|
+
} else if (s === 'criticalPathStage') {
|
|
76
|
+
projectPipelinesSort.push(sortScript.criticalPathStage(sort));
|
|
77
|
+
} else if (s === 'name') {
|
|
78
|
+
projectPipelinesSort.push({
|
|
79
|
+
'name.raw': { order: query.sort, missing: '_last' }
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
projectPipelinesSort.push({
|
|
83
|
+
[s]: { order: query.sort, missing: '_last' }
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (customSort.length > 0) {
|
|
90
|
+
customSort.forEach((cSort) => projectPipelinesSort.push(cSort));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!!query.search) {
|
|
94
|
+
projectPipelinesSort.unshift({
|
|
95
|
+
_score: {
|
|
96
|
+
order: 'desc'
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return projectPipelinesSort;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = new ProjectPipeline();
|
package/lib/taskPipeline.js
CHANGED
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
buildTaskPipelineFilter
|
|
7
7
|
} = require('../helpers/taskFilter');
|
|
8
8
|
const searchFilter = require('../helpers/searchFilter');
|
|
9
|
-
const
|
|
9
|
+
const sortScript = require('../helpers/sortScript');
|
|
10
10
|
|
|
11
11
|
class TaskPipeline {
|
|
12
12
|
taskStatusOptions = taskStatusOptions;
|
|
@@ -91,29 +91,29 @@ class TaskPipeline {
|
|
|
91
91
|
|
|
92
92
|
if (sortByMultiple.length > 0) {
|
|
93
93
|
if (sortByMultiple[0] === 'default') {
|
|
94
|
-
taskPipelinesSort =
|
|
94
|
+
taskPipelinesSort = sortScript.default;
|
|
95
95
|
} else {
|
|
96
96
|
sortByMultiple.forEach((s) => {
|
|
97
97
|
if (s === 'region') {
|
|
98
|
-
taskPipelinesSort.push(
|
|
98
|
+
taskPipelinesSort.push(sortScript.region(sort));
|
|
99
99
|
} else if (s === 'owner' || s === 'completed_by') {
|
|
100
|
-
taskPipelinesSort.push(
|
|
100
|
+
taskPipelinesSort.push(sortScript.owner(sort));
|
|
101
101
|
} else if (s === 'status') {
|
|
102
|
-
taskPipelinesSort.push(
|
|
102
|
+
taskPipelinesSort.push(sortScript.status(sort));
|
|
103
103
|
} else if (s === 'critical_path_stage') {
|
|
104
|
-
taskPipelinesSort.push(
|
|
104
|
+
taskPipelinesSort.push(sortScript.criticalPathStage(sort));
|
|
105
105
|
} else if (s === 'project_id') {
|
|
106
106
|
// Sort numeric part of the Project ID
|
|
107
|
-
taskPipelinesSort.push(
|
|
107
|
+
taskPipelinesSort.push(sortScript.projectId(sort));
|
|
108
108
|
} else if (s === 'ready_at') {
|
|
109
|
-
taskPipelinesSort.push(
|
|
109
|
+
taskPipelinesSort.push(sortScript.readyAt(sort));
|
|
110
110
|
} else if (s === 'was_marked_incomplete') {
|
|
111
|
-
taskPipelinesSort.push(
|
|
111
|
+
taskPipelinesSort.push(sortScript.wasMarkedIncomplete(sort));
|
|
112
112
|
} else if (s === 'last_comment_date') {
|
|
113
|
-
taskPipelinesSort.push(
|
|
113
|
+
taskPipelinesSort.push(sortScript.lastCommentDate(sort));
|
|
114
114
|
} else if (isUuid(s)) {
|
|
115
|
-
taskPipelinesSort.push(
|
|
116
|
-
taskPipelinesSort.push(
|
|
115
|
+
taskPipelinesSort.push(sortScript.projectFieldNumeric(sort, s));
|
|
116
|
+
taskPipelinesSort.push(sortScript.projectFieldText(sort, s));
|
|
117
117
|
} else {
|
|
118
118
|
taskPipelinesSort.push({
|
|
119
119
|
[s]: { order: sort, missing: '_last' }
|
|
@@ -123,7 +123,7 @@ class TaskPipeline {
|
|
|
123
123
|
}
|
|
124
124
|
} else {
|
|
125
125
|
// Default sorting
|
|
126
|
-
taskPipelinesSort =
|
|
126
|
+
taskPipelinesSort = sortScript.default;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (customSort.length > 0) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outliant/sunrise-utils",
|
|
3
3
|
"description": "Helper functions for project Sunrise",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Outliant",
|
|
7
7
|
"main": "index.js",
|
|
@@ -66,8 +66,5 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"moment": "^2.29.4",
|
|
68
68
|
"uuid": "^9.0.0"
|
|
69
|
-
},
|
|
70
|
-
"publishConfig": {
|
|
71
|
-
"access": "public"
|
|
72
69
|
}
|
|
73
70
|
}
|
|
File without changes
|