@outliant/sunrise-utils 1.4.8 → 2.0.2
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 +15 -0
- package/README.md +20 -0
- package/helpers/projectFilter/criticalPathAgeFilter.js +4 -4
- package/helpers/projectFilter/projectFieldFilter.js +491 -467
- package/helpers/searchFilter.js +55 -70
- package/helpers/sortScript.js +6 -0
- package/index.d.ts +7 -0
- package/index.js +2 -0
- package/lib/common.js +19 -0
- package/lib/projectPipeline.js +23 -27
- package/package.json +3 -3
package/helpers/searchFilter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const { validate: isUuid } = require('uuid');
|
|
1
|
+
// const { validate: isUuid } = require('uuid');
|
|
2
2
|
const { escapeElasticQuery } = require('./es');
|
|
3
|
+
const { isPipelineField } = require('../lib/common');
|
|
3
4
|
|
|
4
5
|
module.exports = (query = {}, searchFields = []) => {
|
|
5
6
|
const search = query.search;
|
|
@@ -14,8 +15,10 @@ module.exports = (query = {}, searchFields = []) => {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
const should = [];
|
|
17
|
-
const
|
|
18
|
-
const localFields = searchFields.filter(
|
|
18
|
+
const pipelineFields = searchFields.filter((x) => isPipelineField(x));
|
|
19
|
+
const localFields = searchFields.filter(
|
|
20
|
+
(x) => x !== '_id' && !isPipelineField(x)
|
|
21
|
+
);
|
|
19
22
|
|
|
20
23
|
if (searchFields.includes('_id')) {
|
|
21
24
|
should.push({
|
|
@@ -70,33 +73,15 @@ module.exports = (query = {}, searchFields = []) => {
|
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
if (
|
|
74
|
-
for (let i = 0; i <
|
|
76
|
+
if (pipelineFields.length > 0) {
|
|
77
|
+
for (let i = 0; i < pipelineFields.length; i++) {
|
|
75
78
|
should.push({
|
|
76
79
|
function_score: {
|
|
77
80
|
query: {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
must: [
|
|
83
|
-
{
|
|
84
|
-
term: {
|
|
85
|
-
'fields.id': {
|
|
86
|
-
value: projectFields[i]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
match: {
|
|
92
|
-
'fields.text.analyzed': {
|
|
93
|
-
query: searchString,
|
|
94
|
-
operator: isQueryQuoteWrapped ? 'and' : 'or'
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
]
|
|
99
|
-
}
|
|
81
|
+
match: {
|
|
82
|
+
[`${pipelineFields[i]}.value`]: {
|
|
83
|
+
query: searchString,
|
|
84
|
+
operator: isQueryQuoteWrapped ? 'and' : 'or'
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
87
|
},
|
|
@@ -104,49 +89,49 @@ module.exports = (query = {}, searchFields = []) => {
|
|
|
104
89
|
}
|
|
105
90
|
});
|
|
106
91
|
|
|
107
|
-
should.push({
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
});
|
|
92
|
+
// should.push({
|
|
93
|
+
// bool: {
|
|
94
|
+
// must: [
|
|
95
|
+
// {
|
|
96
|
+
// nested: {
|
|
97
|
+
// path: 'fields',
|
|
98
|
+
// query: {
|
|
99
|
+
// bool: {
|
|
100
|
+
// must: [
|
|
101
|
+
// {
|
|
102
|
+
// term: {
|
|
103
|
+
// 'fields.id': {
|
|
104
|
+
// value: projectFields[i]
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// },
|
|
108
|
+
// {
|
|
109
|
+
// bool: {
|
|
110
|
+
// should: [
|
|
111
|
+
// {
|
|
112
|
+
// match: {
|
|
113
|
+
// [`fields.text.analyzed`]: {
|
|
114
|
+
// query: searchString,
|
|
115
|
+
// operator: 'and'
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
118
|
+
// },
|
|
119
|
+
// {
|
|
120
|
+
// match_phrase_prefix: {
|
|
121
|
+
// [`fields.text.analyzed`]: searchString
|
|
122
|
+
// }
|
|
123
|
+
// }
|
|
124
|
+
// ]
|
|
125
|
+
// }
|
|
126
|
+
// }
|
|
127
|
+
// ]
|
|
128
|
+
// }
|
|
129
|
+
// }
|
|
130
|
+
// }
|
|
131
|
+
// }
|
|
132
|
+
// ]
|
|
133
|
+
// }
|
|
134
|
+
// });
|
|
150
135
|
}
|
|
151
136
|
}
|
|
152
137
|
|
package/helpers/sortScript.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -99,6 +99,13 @@ declare namespace Utils {
|
|
|
99
99
|
export function getNotIsPausedQuery(): any;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
namespace common {
|
|
103
|
+
export function isProjectField(field: string): boolean;
|
|
104
|
+
export function isTaskField(field: string): boolean;
|
|
105
|
+
export function isContactField(field: string): boolean;
|
|
106
|
+
export function isPipelineField(field: string): boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
102
109
|
interface SNSService {
|
|
103
110
|
publishBatch(params: {
|
|
104
111
|
TopicArn: string;
|
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const log = require('./lib/logger');
|
|
2
|
+
const common = require('./lib/common');
|
|
2
3
|
const fieldConditions = require('./lib/fieldConditions');
|
|
3
4
|
const taskPipeline = require('./lib/taskPipeline');
|
|
4
5
|
const projectPipeline = require('./lib/projectPipeline');
|
|
@@ -7,6 +8,7 @@ const queries = require('./lib/queries');
|
|
|
7
8
|
const EventService = require('./lib/eventService');
|
|
8
9
|
|
|
9
10
|
module.exports = {
|
|
11
|
+
common,
|
|
10
12
|
log,
|
|
11
13
|
fieldConditions,
|
|
12
14
|
taskPipeline,
|
package/lib/common.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports.isProjectField = (field) => {
|
|
2
|
+
return field.startsWith('project_fields.');
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
module.exports.isTaskField = (field) => {
|
|
6
|
+
return field.startsWith('task_fields.');
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports.isContactField = (field) => {
|
|
10
|
+
return field.startsWith('contact_fields.');
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports.isPipelineField = (field) => {
|
|
14
|
+
return (
|
|
15
|
+
module.exports.isProjectField(field) ||
|
|
16
|
+
module.exports.isTaskField(field) ||
|
|
17
|
+
module.exports.isContactField(field)
|
|
18
|
+
);
|
|
19
|
+
};
|
package/lib/projectPipeline.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _ = require('lodash');
|
|
2
2
|
const {
|
|
3
3
|
defaultCustomColumns,
|
|
4
4
|
buildProjectPipelineFilter,
|
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
const searchFilter = require('../helpers/searchFilter');
|
|
8
8
|
const sortScript = require('../helpers/sortScript');
|
|
9
9
|
const sourceParams = require('../helpers/sourceParams');
|
|
10
|
+
const { isPipelineField } = require('../lib/common');
|
|
10
11
|
|
|
11
12
|
class ProjectPipeline {
|
|
12
13
|
defaultCustomColumns = defaultCustomColumns;
|
|
@@ -31,21 +32,11 @@ class ProjectPipeline {
|
|
|
31
32
|
];
|
|
32
33
|
|
|
33
34
|
if (departmentId) {
|
|
34
|
-
mustQuery.push(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
: {
|
|
42
|
-
term: {
|
|
43
|
-
department_id: {
|
|
44
|
-
value: departmentId
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
);
|
|
35
|
+
mustQuery.push({
|
|
36
|
+
terms: {
|
|
37
|
+
department_id: _.castArray(departmentId)
|
|
38
|
+
}
|
|
39
|
+
});
|
|
49
40
|
}
|
|
50
41
|
|
|
51
42
|
if (query.search && query.search.length > 0) {
|
|
@@ -61,16 +52,22 @@ class ProjectPipeline {
|
|
|
61
52
|
}
|
|
62
53
|
|
|
63
54
|
if (query.projectIds && query.projectIds.length) {
|
|
64
|
-
const should = query.projectIds.map((projectId) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
55
|
+
// const should = query.projectIds.map((projectId) => {
|
|
56
|
+
// return {
|
|
57
|
+
// match: {
|
|
58
|
+
// _id: projectId
|
|
59
|
+
// }
|
|
60
|
+
// };
|
|
61
|
+
// });
|
|
62
|
+
|
|
63
|
+
// mustQuery.push({
|
|
64
|
+
// bool: { should }
|
|
65
|
+
// });
|
|
71
66
|
|
|
72
67
|
mustQuery.push({
|
|
73
|
-
|
|
68
|
+
terms: {
|
|
69
|
+
_id: query.projectIds
|
|
70
|
+
}
|
|
74
71
|
});
|
|
75
72
|
}
|
|
76
73
|
|
|
@@ -103,9 +100,8 @@ class ProjectPipeline {
|
|
|
103
100
|
const sort = sortMultiple[i] || 'desc';
|
|
104
101
|
|
|
105
102
|
switch (true) {
|
|
106
|
-
case
|
|
107
|
-
projectPipelinesSort.push(sortScript.
|
|
108
|
-
projectPipelinesSort.push(sortScript.projectFieldText(sort, s));
|
|
103
|
+
case isPipelineField(s):
|
|
104
|
+
projectPipelinesSort.push(sortScript.projectField(sort, s));
|
|
109
105
|
break;
|
|
110
106
|
|
|
111
107
|
case s === 'region':
|
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": "
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Outliant",
|
|
7
7
|
"main": "index.js",
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
],
|
|
37
37
|
"husky": {
|
|
38
38
|
"hooks": {
|
|
39
|
-
"pre-commit": "npm run lint"
|
|
40
|
-
"pre-push": "npm run test"
|
|
39
|
+
"pre-commit": "npm run lint"
|
|
41
40
|
}
|
|
42
41
|
},
|
|
43
42
|
"prettier": {
|
|
@@ -64,6 +63,7 @@
|
|
|
64
63
|
"statements": 50
|
|
65
64
|
},
|
|
66
65
|
"dependencies": {
|
|
66
|
+
"lodash": "^4.17.21",
|
|
67
67
|
"moment": "^2.29.4",
|
|
68
68
|
"uuid": "^9.0.0"
|
|
69
69
|
}
|