@outliant/sunrise-utils 1.3.10 → 1.4.1

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 CHANGED
@@ -4,8 +4,23 @@ 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.4.1](https://github.com/outliant/sunrise-utils/compare/1.4.0...1.4.1)
8
+
9
+ - chore: minor fix [`b006891`](https://github.com/outliant/sunrise-utils/commit/b0068914ca0c23a99a1badde04131ba296898e52)
10
+ - chore: minor fix [`9d6a965`](https://github.com/outliant/sunrise-utils/commit/9d6a9657094b92873c948c1071edb9aa85a33b81)
11
+
12
+ #### [1.4.0](https://github.com/outliant/sunrise-utils/compare/1.3.10...1.4.0)
13
+
14
+ > 8 April 2025
15
+
16
+ - chore: refactor task/project pipeline common filters #86b4dg28t [`54a12a9`](https://github.com/outliant/sunrise-utils/commit/54a12a9e80ea402825bd64589efdf91b65c207a1)
17
+ - chore(release): 1.4.0 [`9ce7737`](https://github.com/outliant/sunrise-utils/commit/9ce7737cbb222b68ab84dcf6ed0fe8841732ad38)
18
+
7
19
  #### [1.3.10](https://github.com/outliant/sunrise-utils/compare/1.3.9...1.3.10)
8
20
 
21
+ > 27 March 2025
22
+
23
+ - chore(release): 1.3.10 [`f5348f0`](https://github.com/outliant/sunrise-utils/commit/f5348f0115b50d232fb85fe4cd1f3201116da6a6)
9
24
  - chore: task_age updates [`02ad141`](https://github.com/outliant/sunrise-utils/commit/02ad141886dc8ae4a16da3173a016402316fbae3)
10
25
 
11
26
  #### [1.3.9](https://github.com/outliant/sunrise-utils/compare/1.3.8...1.3.9)
@@ -0,0 +1,628 @@
1
+ const moment = require('moment');
2
+
3
+ const splitString = require('./splitString');
4
+ const { isNoneOf } = require('./common');
5
+
6
+ module.exports = (filter) => {
7
+ if (!filter.type) return null;
8
+
9
+ switch (filter.condition) {
10
+ case 'contains_any':
11
+ return module.exports.containsAny(filter);
12
+ case 'contains_none':
13
+ return module.exports.containsNone(filter);
14
+ case 'contains_all':
15
+ return module.exports.containsAll(filter);
16
+ case 'is_any_of':
17
+ return module.exports.isAnyOf(filter);
18
+ case 'is_empty':
19
+ return module.exports.isEmpty(filter);
20
+ case 'is_not_empty':
21
+ return module.exports.isNotEmpty(filter);
22
+ case 'is_equal':
23
+ if (filter.type === 'ready_at') {
24
+ return module.exports.isReadyAt(filter);
25
+ }
26
+ return module.exports.isEqual(filter);
27
+ case 'not_equal':
28
+ return module.exports.isNotEqual(filter);
29
+ case 'is_none_of':
30
+ return isNoneOf(filter, module.exports.isEqual);
31
+ case 'before':
32
+ case 'less_than':
33
+ return module.exports.isBefore(filter);
34
+ case 'after':
35
+ case 'greater_than':
36
+ return module.exports.isAfter(filter);
37
+ case 'less_than_or_equal':
38
+ return module.exports.isBeforeIncludeParam(filter);
39
+ case 'greater_than_or_equal':
40
+ return module.exports.isAfterIncludeParam(filter);
41
+ case 'between':
42
+ return module.exports.isBetween(filter);
43
+ case 'next_n_days':
44
+ return module.exports.nextNDays(filter);
45
+ case 'last_n_days':
46
+ return module.exports.lastNDays(filter);
47
+ case 'greater_n_days_ago':
48
+ return module.exports.greaterNDaysAgo(filter);
49
+ case 'is_true':
50
+ return module.exports.isTrue(filter);
51
+ case 'is_false':
52
+ return module.exports.isFalse(filter);
53
+ default:
54
+ return null;
55
+ }
56
+ };
57
+
58
+ module.exports.containsAny = (filter) => {
59
+ const type = filter.field_type || filter.type;
60
+
61
+ if (['text', 'textarea'].includes(type)) {
62
+ return {
63
+ match: {
64
+ [filter.type]: {
65
+ query: filter.value,
66
+ fuzziness: 'AUTO'
67
+ }
68
+ }
69
+ };
70
+ } else if (['checkbox', 'select'].includes(type)) {
71
+ const value =
72
+ typeof filter.value === 'string'
73
+ ? splitString(filter.value)
74
+ : filter.value;
75
+
76
+ return {
77
+ terms: {
78
+ [filter.type]: value
79
+ }
80
+ };
81
+ }
82
+
83
+ return null;
84
+ };
85
+
86
+ module.exports.containsAll = (filter) => {
87
+ const type = filter.field_type || filter.type;
88
+
89
+ if (['text', 'textarea'].includes(type)) {
90
+ return {
91
+ match: {
92
+ [filter.type]: {
93
+ query: filter.value,
94
+ fuzziness: 'AUTO'
95
+ }
96
+ }
97
+ };
98
+ } else if (['checkbox', 'select'].includes(type)) {
99
+ const value =
100
+ typeof filter.value === 'string'
101
+ ? splitString(filter.value)
102
+ : filter.value;
103
+
104
+ return {
105
+ bool: {
106
+ must: value.map((val) => ({
107
+ term: {
108
+ [filter.type]: {
109
+ value: val
110
+ }
111
+ }
112
+ }))
113
+ }
114
+ };
115
+ }
116
+
117
+ return null;
118
+ };
119
+
120
+ module.exports.containsNone = (filter) => {
121
+ const type = filter.field_type || filter.type;
122
+
123
+ if (['text', 'textarea'].includes(type)) {
124
+ return {
125
+ bool: {
126
+ must_not: [
127
+ {
128
+ match: {
129
+ [filter.type]: {
130
+ query: filter.value,
131
+ fuzziness: 'AUTO'
132
+ }
133
+ }
134
+ }
135
+ ]
136
+ }
137
+ };
138
+ } else if (['checkbox', 'select'].includes(type)) {
139
+ const value =
140
+ typeof filter.value === 'string'
141
+ ? splitString(filter.value)
142
+ : filter.value;
143
+
144
+ return {
145
+ bool: {
146
+ must_not: [
147
+ {
148
+ terms: {
149
+ [filter.type]: value
150
+ }
151
+ }
152
+ ]
153
+ }
154
+ };
155
+ }
156
+
157
+ return null;
158
+ };
159
+
160
+ module.exports.isAnyOf = (filter) => {
161
+ const type = filter.field_type || filter.type;
162
+
163
+ if (['text', 'textarea'].includes(type)) {
164
+ return {
165
+ match: {
166
+ [filter.type]: {
167
+ query: filter.value,
168
+ fuzziness: 'AUTO'
169
+ }
170
+ }
171
+ };
172
+ } else {
173
+ const value =
174
+ typeof filter.value === 'string'
175
+ ? splitString(filter.value)
176
+ : filter.value;
177
+
178
+ return {
179
+ terms: {
180
+ [filter.type]: value
181
+ }
182
+ };
183
+ }
184
+ };
185
+
186
+ module.exports.isEmpty = (filter) => {
187
+ if (filter.field_type === 'text' || filter.field_type === 'textarea') {
188
+ return {
189
+ bool: {
190
+ should: [
191
+ {
192
+ bool: {
193
+ must_not: [
194
+ {
195
+ exists: {
196
+ field: filter.type
197
+ }
198
+ }
199
+ ]
200
+ }
201
+ },
202
+ {
203
+ bool: {
204
+ must_not: [
205
+ {
206
+ wildcard: {
207
+ [filter.type]: {
208
+ value: '?*'
209
+ }
210
+ }
211
+ }
212
+ ]
213
+ }
214
+ },
215
+ {
216
+ term: {
217
+ [filter.type]: {
218
+ value: ''
219
+ }
220
+ }
221
+ }
222
+ ]
223
+ }
224
+ };
225
+ }
226
+ return {
227
+ bool: {
228
+ should: [
229
+ {
230
+ term: {
231
+ [filter.type]: {
232
+ value: ''
233
+ }
234
+ }
235
+ },
236
+ {
237
+ bool: {
238
+ must_not: [
239
+ {
240
+ exists: {
241
+ field: filter.type
242
+ }
243
+ }
244
+ ]
245
+ }
246
+ }
247
+ ]
248
+ }
249
+ };
250
+ };
251
+
252
+ module.exports.isNotEmpty = (filter) => {
253
+ if (filter.field_type === 'text' || filter.field_type === 'textarea') {
254
+ return {
255
+ bool: {
256
+ must: [
257
+ {
258
+ exists: {
259
+ field: filter.type
260
+ }
261
+ },
262
+ {
263
+ wildcard: {
264
+ [filter.type]: {
265
+ value: '?*'
266
+ }
267
+ }
268
+ },
269
+ {
270
+ bool: {
271
+ must_not: [
272
+ {
273
+ term: {
274
+ [filter.type]: {
275
+ value: ''
276
+ }
277
+ }
278
+ }
279
+ ]
280
+ }
281
+ }
282
+ ]
283
+ }
284
+ };
285
+ }
286
+
287
+ return {
288
+ bool: {
289
+ must_not: [
290
+ {
291
+ term: {
292
+ [filter.type]: {
293
+ value: ''
294
+ }
295
+ }
296
+ }
297
+ ],
298
+ must: [
299
+ {
300
+ exists: {
301
+ field: filter.type
302
+ }
303
+ }
304
+ ]
305
+ }
306
+ };
307
+ };
308
+
309
+ module.exports.isEqual = (filter) => {
310
+ if (filter.field_type === 'date') {
311
+ const startOfDay = moment(filter.value).startOf('day').valueOf();
312
+ const endOfDay = moment(filter.value).endOf('day').valueOf();
313
+
314
+ return {
315
+ range: {
316
+ [filter.type]: {
317
+ gte: startOfDay,
318
+ lte: endOfDay
319
+ }
320
+ }
321
+ };
322
+ }
323
+
324
+ if (filter.field_type === 'textarea') {
325
+ return {
326
+ query_string: {
327
+ fields: [filter.type],
328
+ query: `*${filter.value}*`
329
+ }
330
+ };
331
+ }
332
+
333
+ if (filter.field_type === 'checkbox') {
334
+ const value =
335
+ typeof filter.value === 'string'
336
+ ? splitString(filter.value)
337
+ : filter.value;
338
+
339
+ const should = [];
340
+
341
+ value.forEach((x) => {
342
+ should.push({
343
+ match: {
344
+ [`${filter.type}.analyzed`]: {
345
+ query: x,
346
+ operator: 'and'
347
+ }
348
+ }
349
+ });
350
+
351
+ should.push({
352
+ term: {
353
+ [filter.type]: {
354
+ value: x
355
+ }
356
+ }
357
+ });
358
+ });
359
+
360
+ return {
361
+ bool: {
362
+ should
363
+ }
364
+ };
365
+ }
366
+
367
+ if (filter.field_type === 'number') {
368
+ return {
369
+ term: {
370
+ [filter.type]: {
371
+ value: parseInt(filter.value)
372
+ }
373
+ }
374
+ };
375
+ }
376
+
377
+ return {
378
+ term: {
379
+ [filter.type]: {
380
+ value: filter.value
381
+ }
382
+ }
383
+ };
384
+ };
385
+
386
+ module.exports.isReadyAt = (filter) => {
387
+ const startOfDay = moment(filter.value).startOf('day').valueOf();
388
+ const endOfDay = moment(filter.value).endOf('day').valueOf();
389
+
390
+ return {
391
+ script: {
392
+ script: {
393
+ source: `
394
+ try {
395
+ def filterType = params.filterType;
396
+ def taskFilter = doc[filterType];
397
+
398
+ if (taskFilter.size() == 0) {
399
+ return false;
400
+ }
401
+
402
+ long startOfDay = params.startOfDay;
403
+ long endOfDay = params.endOfDay;
404
+
405
+ if (
406
+ filterType == 'ready_at' &&
407
+ doc['is_complete'].size() != 0 &&
408
+ doc['is_complete'].value == true &&
409
+ doc['completed_at'].size() != 0
410
+ ) {
411
+ long completedAt = doc['completed_at'].value.millis;
412
+ return completedAt >= startOfDay && completedAt <= endOfDay;
413
+ } else {
414
+ long taskFilterValue = taskFilter.value.millis;
415
+ return taskFilterValue >= startOfDay && taskFilterValue <= endOfDay;
416
+ }
417
+ } catch(Exception err){
418
+ return false;
419
+ }`,
420
+ lang: 'painless',
421
+ params: {
422
+ startOfDay,
423
+ endOfDay,
424
+ filterType: filter.type
425
+ }
426
+ }
427
+ }
428
+ };
429
+ };
430
+
431
+ module.exports.isBefore = (filter) => {
432
+ let param;
433
+
434
+ if (filter.field_type === 'date') {
435
+ param = moment(filter.value).startOf('day').valueOf();
436
+ } else if (filter.field_type === 'number') {
437
+ param = parseInt(filter.value);
438
+ } else {
439
+ return null;
440
+ }
441
+
442
+ return {
443
+ range: {
444
+ [filter.type]: {
445
+ lt: param
446
+ }
447
+ }
448
+ };
449
+ };
450
+
451
+ module.exports.isAfter = (filter) => {
452
+ let param;
453
+
454
+ if (filter.field_type === 'date') {
455
+ param = moment(filter.value).endOf('day').valueOf();
456
+ } else if (filter.field_type === 'number') {
457
+ param = parseInt(filter.value);
458
+ } else {
459
+ return null;
460
+ }
461
+
462
+ return {
463
+ range: {
464
+ [filter.type]: {
465
+ gt: param
466
+ }
467
+ }
468
+ };
469
+ };
470
+
471
+ module.exports.nextNDays = (filter) => {
472
+ if (isNaN(filter.value)) {
473
+ return null;
474
+ }
475
+
476
+ return {
477
+ range: {
478
+ [filter.type]: {
479
+ lt: `now/d+${filter.value}d`,
480
+ gt: 'now/d'
481
+ }
482
+ }
483
+ };
484
+ };
485
+
486
+ module.exports.lastNDays = (filter) => {
487
+ if (isNaN(filter.value)) {
488
+ return null;
489
+ }
490
+
491
+ return {
492
+ range: {
493
+ [filter.type]: {
494
+ gt: `now/d-${filter.value}d`,
495
+ lt: 'now/d'
496
+ }
497
+ }
498
+ };
499
+ };
500
+
501
+ module.exports.greaterNDaysAgo = (filter) => {
502
+ if (isNaN(filter.value)) {
503
+ return null;
504
+ }
505
+
506
+ return {
507
+ range: {
508
+ [filter.type]: {
509
+ lt: `now/d-${filter.value}d`
510
+ }
511
+ }
512
+ };
513
+ };
514
+
515
+ module.exports.isBeforeIncludeParam = (filter) => {
516
+ let param;
517
+
518
+ if (filter.field_type === 'date') {
519
+ param = moment(filter.value).endOf('day').valueOf();
520
+ } else if (filter.field_type === 'number') {
521
+ param = parseInt(filter.value);
522
+ } else {
523
+ return null;
524
+ }
525
+
526
+ return {
527
+ range: {
528
+ [filter.type]: {
529
+ lte: param
530
+ }
531
+ }
532
+ };
533
+ };
534
+
535
+ module.exports.isAfterIncludeParam = (filter) => {
536
+ let param;
537
+
538
+ if (filter.field_type === 'date') {
539
+ param = moment(filter.value).endOf('day').valueOf();
540
+ } else if (filter.field_type === 'number') {
541
+ param = parseInt(filter.value);
542
+ } else {
543
+ return null;
544
+ }
545
+
546
+ return {
547
+ range: {
548
+ [filter.type]: {
549
+ gte: param
550
+ }
551
+ }
552
+ };
553
+ };
554
+
555
+ module.exports.isBetween = (filter) => {
556
+ let firstParam;
557
+ let secondParam;
558
+
559
+ if (filter.field_type === 'date') {
560
+ firstParam = moment(filter.value).startOf('day').valueOf();
561
+ secondParam = moment(filter.second_value).endOf('day').valueOf();
562
+ } else if (filter.field_type === 'number') {
563
+ firstParam = parseInt(filter.value);
564
+ secondParam = parseInt(filter.second_value);
565
+ } else {
566
+ return null;
567
+ }
568
+
569
+ return {
570
+ range: {
571
+ [filter.type]: {
572
+ gte: firstParam,
573
+ lte: secondParam
574
+ }
575
+ }
576
+ };
577
+ };
578
+
579
+ module.exports.isNotEqual = (filter) => {
580
+ const equalFilter = module.exports.isEqual(filter);
581
+
582
+ if (equalFilter) {
583
+ return {
584
+ bool: {
585
+ must_not: equalFilter
586
+ }
587
+ };
588
+ }
589
+
590
+ return null;
591
+ };
592
+
593
+ module.exports.isTrue = (filter) => {
594
+ if (filter.field_type !== 'boolean') return null;
595
+
596
+ return {
597
+ term: {
598
+ [filter.type]: {
599
+ value: true
600
+ }
601
+ }
602
+ };
603
+ };
604
+
605
+ module.exports.isFalse = (filter) => {
606
+ if (filter.field_type !== 'boolean') return null;
607
+
608
+ return {
609
+ bool: {
610
+ should: [
611
+ {
612
+ match: {
613
+ [filter.type]: false
614
+ }
615
+ },
616
+ {
617
+ bool: {
618
+ must_not: {
619
+ exists: {
620
+ field: filter.type
621
+ }
622
+ }
623
+ }
624
+ }
625
+ ]
626
+ }
627
+ };
628
+ };
@@ -4,9 +4,10 @@ const buildCriticalPathAgeFilter = require('./criticalPathAgeFilter');
4
4
  const buildOnHoldFilter = require('./onHoldFilter');
5
5
  const buildIsPausedFilter = require('./isPausedFilter');
6
6
  const buildIsGeneratedFilter = require('./isGeneratedFilter');
7
+ const buildProjectIdFilter = require('./projectIdFilter');
7
8
  const buildTagFilter = require('./tagFilter');
8
9
  const buildProjectFieldFilter = require('./projectFieldFilter');
9
- const buildProjectFilter = require('./projectFilter');
10
+ const buildCommonFilter = require('../commonFilter');
10
11
  const { PROJECT_BANNERS } = require('../../constants');
11
12
 
12
13
  module.exports.defaultCustomColumns = [
@@ -143,6 +144,8 @@ module.exports.defaultFilterSetting = {
143
144
 
144
145
  module.exports.buildProjectPipelineFilter = (filter) => {
145
146
  switch (filter.type) {
147
+ case 'project_id':
148
+ return buildProjectIdFilter(filter);
146
149
  case 'tags':
147
150
  return buildTagFilter(filter);
148
151
  case 'region':
@@ -162,6 +165,6 @@ module.exports.buildProjectPipelineFilter = (filter) => {
162
165
  case 'contactPropertyMappings':
163
166
  return buildProjectFieldFilter(filter);
164
167
  default:
165
- return buildProjectFilter(filter);
168
+ return buildCommonFilter(filter);
166
169
  }
167
170
  };
@@ -0,0 +1,62 @@
1
+ module.exports = (filter) => {
2
+ switch (filter.condition) {
3
+ case 'is_equal':
4
+ return module.exports.isEqual(filter);
5
+ case 'not_equal':
6
+ return module.exports.isNotEqual(filter);
7
+ case 'is_any_of':
8
+ return module.exports.isEqual(filter);
9
+ case 'is_none_of':
10
+ return module.exports.isNotEqual(filter);
11
+ case 'contains_any':
12
+ return module.exports.containsAny(filter);
13
+ case 'contains_none':
14
+ return module.exports.containsNone(filter);
15
+ default:
16
+ return null;
17
+ }
18
+ };
19
+
20
+ module.exports.isEqual = (filter) => {
21
+ return {
22
+ match: {
23
+ _id: (filter.value || '').toUpperCase()
24
+ }
25
+ };
26
+ };
27
+
28
+ module.exports.isNotEqual = (filter) => {
29
+ return {
30
+ bool: {
31
+ must_not: {
32
+ match: {
33
+ _id: (filter.value || '').toUpperCase()
34
+ }
35
+ }
36
+ }
37
+ };
38
+ };
39
+
40
+ module.exports.containsAny = (filter) => {
41
+ return {
42
+ wildcard: {
43
+ id: {
44
+ value: `*${(filter.value || '').toUpperCase()}*`
45
+ }
46
+ }
47
+ };
48
+ };
49
+
50
+ module.exports.containsNone = (filter) => {
51
+ return {
52
+ bool: {
53
+ must_not: {
54
+ wildcard: {
55
+ id: {
56
+ value: `*${(filter.value || '').toUpperCase()}*`
57
+ }
58
+ }
59
+ }
60
+ }
61
+ };
62
+ };
@@ -1,8 +1,7 @@
1
1
  const { validate: isUuid } = require('uuid');
2
2
  const { escapeElasticQuery } = require('./es');
3
- const _ = require('lodash');
4
3
 
5
- module.exports = (query = {}, searchFields = [], isGlobalSearch = false) => {
4
+ module.exports = (query = {}, searchFields = []) => {
6
5
  const search = query.search;
7
6
  let searchString = search.trim();
8
7
 
@@ -19,42 +18,30 @@ module.exports = (query = {}, searchFields = [], isGlobalSearch = false) => {
19
18
  const localFields = searchFields.filter((x) => x !== '_id' && !isUuid(x));
20
19
 
21
20
  if (searchFields.includes('_id')) {
22
- should.push(
23
- isGlobalSearch
24
- ? {
25
- bool: {
26
- should: _.flatMap(
27
- _.split(_.replace(searchString, /ser-|com-/gi, ''), ' ').filter(Boolean),
28
- term => [
29
- { term: { _id: `SER-${term}` } },
30
- { term: { _id: `COM-${term}` } },
31
- { term: { _id: term } }
32
- ]
33
- )
34
- }
35
- }
36
- : {
37
- term: {
38
- _id: {
39
- value: searchString
40
- }
41
- }
42
- }
43
- );
21
+ should.push({
22
+ match: {
23
+ _id: searchString
24
+ }
25
+ });
44
26
  }
45
27
 
46
- if (!isGlobalSearch) {
47
- /**
48
- * For case insensitive id search with hyphen
49
- */
50
- _.split(search, '-').forEach(keyword => {
51
- should.push({
52
- wildcard: {
53
- id: {
54
- value: `*${keyword}*`
55
- }
28
+ if (searchFields.includes('id')) {
29
+ should.push({
30
+ wildcard: {
31
+ id: {
32
+ value: `*${searchString.toUpperCase()}*`
56
33
  }
57
- });
34
+ }
35
+ });
36
+ }
37
+
38
+ if (searchFields.includes('project_id')) {
39
+ should.push({
40
+ wildcard: {
41
+ project_id: {
42
+ value: `*${searchString.toUpperCase()}*`
43
+ }
44
+ }
58
45
  });
59
46
  }
60
47
 
@@ -3,6 +3,7 @@ const buildOwnerFilter = require('./ownerFilter');
3
3
  const buildPathAgeFilter = require('./pathAgeFilter');
4
4
  const buildRegionFilter = require('./regionFilter');
5
5
  const buildTaskFieldFilter = require('./taskFieldFilter');
6
+ const buildProjectIdFilter = require('./projectIdFilter');
6
7
  const buildCriticalPathFilter = require('./criticalPathFilter');
7
8
  const buildOnHoldFilter = require('./onHoldFilter');
8
9
  const buildIsPausedFilter = require('./isPausedFilter');
@@ -11,6 +12,7 @@ const buildDaysToCompleteFilter = require('./daysToComplete');
11
12
  const buildAgeColorFilter = require('./buildAgeColorFilter');
12
13
  const buildWasMarkedIncompleteFilter = require('./wasMarkedIncomplete');
13
14
  const buildProjectFieldFilter = require('../projectFilter/projectFieldFilter');
15
+ const buildCommonFilter = require('../commonFilter');
14
16
  const { PROJECT_BANNERS } = require('../../constants');
15
17
  const splitString = require('../splitString');
16
18
 
@@ -327,6 +329,8 @@ module.exports.defaultFilterSetting = {
327
329
 
328
330
  module.exports.buildTaskPipelineFilter = (filter, starredTaskIds) => {
329
331
  switch (filter.type) {
332
+ case 'project_id':
333
+ return buildProjectIdFilter(filter);
330
334
  case 'status':
331
335
  return buildStatusFilter(filter);
332
336
  case 'owner':
@@ -390,7 +394,6 @@ module.exports.buildTaskPipelineFilter = (filter, starredTaskIds) => {
390
394
  case 'is_starred':
391
395
  return buildIsStarredFilter(filter, starredTaskIds);
392
396
  default:
393
- // Task Fields
394
- return buildTaskFieldFilter(filter);
397
+ return buildCommonFilter(filter);
395
398
  }
396
399
  };
@@ -0,0 +1,62 @@
1
+ module.exports = (filter) => {
2
+ switch (filter.condition) {
3
+ case 'is_equal':
4
+ return module.exports.isEqual(filter);
5
+ case 'not_equal':
6
+ return module.exports.isNotEqual(filter);
7
+ case 'is_any_of':
8
+ return module.exports.isEqual(filter);
9
+ case 'is_none_of':
10
+ return module.exports.isNotEqual(filter);
11
+ case 'contains_any':
12
+ return module.exports.containsAny(filter);
13
+ case 'contains_none':
14
+ return module.exports.containsNone(filter);
15
+ default:
16
+ return null;
17
+ }
18
+ };
19
+
20
+ module.exports.isEqual = (filter) => {
21
+ return {
22
+ match: {
23
+ project_id: (filter.value || '').toUpperCase()
24
+ }
25
+ };
26
+ };
27
+
28
+ module.exports.isNotEqual = (filter) => {
29
+ return {
30
+ bool: {
31
+ must_not: {
32
+ match: {
33
+ project_id: (filter.value || '').toUpperCase()
34
+ }
35
+ }
36
+ }
37
+ };
38
+ };
39
+
40
+ module.exports.containsAny = (filter) => {
41
+ return {
42
+ wildcard: {
43
+ project_id: {
44
+ value: `*${(filter.value || '').toUpperCase()}*`
45
+ }
46
+ }
47
+ };
48
+ };
49
+
50
+ module.exports.containsNone = (filter) => {
51
+ return {
52
+ bool: {
53
+ must_not: {
54
+ wildcard: {
55
+ project_id: {
56
+ value: `*${(filter.value || '').toUpperCase()}*`
57
+ }
58
+ }
59
+ }
60
+ }
61
+ };
62
+ };
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.3.10",
4
+ "version": "1.4.1",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",
@@ -2,7 +2,6 @@
2
2
 
3
3
  /* eslint-env node, mocha */
4
4
  const { expect } = require('chai');
5
- const _ = require('lodash');
6
5
 
7
6
  const projectPipeline = require('../../lib/projectPipeline');
8
7
 
@@ -17,48 +16,19 @@ describe('projectPipeline', function () {
17
16
  expected: {
18
17
  bool: {
19
18
  must: [
20
- {
21
- term: {
22
- organization_id: {
23
- value: ORG_ID
24
- }
25
- }
26
- },
27
- {
28
- term: {
29
- department_id: {
30
- value: DEPARTMENT_ID
31
- }
32
- }
33
- },
19
+ { term: { organization_id: { value: 'orgId' } } },
20
+ { term: { department_id: { value: 'department_id' } } },
34
21
  {
35
22
  bool: {
36
23
  should: [
37
- {
38
- wildcard: {
39
- id: {
40
- value: '*COM*'
41
- }
42
- }
43
- },
44
- {
45
- wildcard: {
46
- id: {
47
- value: '*41853*'
48
- }
49
- }
50
- },
24
+ { wildcard: { project_id: { value: '*COM-41853*' } } },
51
25
  {
52
26
  multi_match: {
53
27
  query: 'COM-41853',
54
28
  fields: ['project_id^5']
55
29
  }
56
30
  },
57
- {
58
- match_phrase_prefix: {
59
- name: 'COM-41853'
60
- }
61
- }
31
+ { match_phrase_prefix: { name: 'COM-41853' } }
62
32
  ]
63
33
  }
64
34
  }
@@ -71,48 +41,19 @@ describe('projectPipeline', function () {
71
41
  expected: {
72
42
  bool: {
73
43
  must: [
74
- {
75
- term: {
76
- organization_id: {
77
- value: ORG_ID
78
- }
79
- }
80
- },
81
- {
82
- term: {
83
- department_id: {
84
- value: DEPARTMENT_ID
85
- }
86
- }
87
- },
44
+ { term: { organization_id: { value: 'orgId' } } },
45
+ { term: { department_id: { value: 'department_id' } } },
88
46
  {
89
47
  bool: {
90
48
  should: [
91
- {
92
- wildcard: {
93
- id: {
94
- value: '*com*'
95
- }
96
- }
97
- },
98
- {
99
- wildcard: {
100
- id: {
101
- value: '*41853*'
102
- }
103
- }
104
- },
49
+ { wildcard: { project_id: { value: '*COM-41853*' } } },
105
50
  {
106
51
  multi_match: {
107
52
  query: 'com-41853',
108
53
  fields: ['project_id^5']
109
54
  }
110
55
  },
111
- {
112
- match_phrase_prefix: {
113
- name: 'com-41853'
114
- }
115
- }
56
+ { match_phrase_prefix: { name: 'com-41853' } }
116
57
  ]
117
58
  }
118
59
  }
@@ -125,41 +66,16 @@ describe('projectPipeline', function () {
125
66
  expected: {
126
67
  bool: {
127
68
  must: [
128
- {
129
- term: {
130
- organization_id: {
131
- value: ORG_ID
132
- }
133
- }
134
- },
135
- {
136
- term: {
137
- department_id: {
138
- value: DEPARTMENT_ID
139
- }
140
- }
141
- },
69
+ { term: { organization_id: { value: 'orgId' } } },
70
+ { term: { department_id: { value: 'department_id' } } },
142
71
  {
143
72
  bool: {
144
73
  should: [
74
+ { wildcard: { project_id: { value: '*41853*' } } },
145
75
  {
146
- wildcard: {
147
- id: {
148
- value: '*41853*'
149
- }
150
- }
151
- },
152
- {
153
- multi_match: {
154
- query: '41853',
155
- fields: ['project_id^5']
156
- }
76
+ multi_match: { query: '41853', fields: ['project_id^5'] }
157
77
  },
158
- {
159
- match_phrase_prefix: {
160
- name: '41853'
161
- }
162
- }
78
+ { match_phrase_prefix: { name: '41853' } }
163
79
  ]
164
80
  }
165
81
  }
@@ -180,7 +96,7 @@ describe('projectPipeline', function () {
180
96
  DEPARTMENT_ID,
181
97
  [],
182
98
  query,
183
- ['project_id'],
99
+ ['project_id']
184
100
  );
185
101
 
186
102
  expect(result).to.deep.equal(entry.expected);
@@ -295,44 +211,33 @@ describe('projectPipeline', function () {
295
211
  params.projectSearchFields,
296
212
  true
297
213
  );
298
-
299
214
  expect(result).to.be.deep.equal({
300
215
  bool: {
301
216
  must: [
302
- {
303
- term: {
304
- organization_id: { value: 'orgId' }
305
- }
306
- },
307
- {
308
- term: {
309
- department_id: { value: 'department_id' }
310
- }
311
- },
217
+ { term: { organization_id: { value: 'orgId' } } },
218
+ { term: { department_id: { value: 'department_id' } } },
312
219
  {
313
220
  bool: {
314
221
  should: [
315
222
  {
316
- bool: {
317
- should: _.flatMap(
318
- _.split(_.replace(params.search, /ser-|com-/gi, ''), ' ').filter(Boolean),
319
- term => [
320
- { term: { _id: `SER-${term}` } },
321
- { term: { _id: `COM-${term}` } },
322
- { term: { _id: term } }
323
- ]
324
- )
223
+ match: { _id: '41853 69 SER-69 allan DoNALD Vikram RalPH' }
224
+ },
225
+ {
226
+ wildcard: {
227
+ id: {
228
+ value: '*41853 69 SER-69 ALLAN DONALD VIKRAM RALPH*'
229
+ }
325
230
  }
326
231
  },
327
232
  {
328
233
  multi_match: {
329
- query: params.search,
234
+ query: '41853 69 SER-69 allan DoNALD Vikram RalPH',
330
235
  fields: ['name^5', 'id^5']
331
236
  }
332
237
  },
333
238
  {
334
239
  match_phrase_prefix: {
335
- name: params.search
240
+ name: '41853 69 SER-69 allan DoNALD Vikram RalPH'
336
241
  }
337
242
  },
338
243
  {
@@ -345,13 +250,17 @@ describe('projectPipeline', function () {
345
250
  must: [
346
251
  {
347
252
  term: {
348
- 'fields.id': { value: '4ef2760a-083a-466b-b761-667856aeb5ee' }
253
+ 'fields.id': {
254
+ value:
255
+ '4ef2760a-083a-466b-b761-667856aeb5ee'
256
+ }
349
257
  }
350
258
  },
351
259
  {
352
260
  match: {
353
261
  'fields.text.analyzed': {
354
- query: params.search,
262
+ query:
263
+ '41853 69 SER-69 allan DoNALD Vikram RalPH',
355
264
  operator: 'or'
356
265
  }
357
266
  }
@@ -375,7 +284,10 @@ describe('projectPipeline', function () {
375
284
  must: [
376
285
  {
377
286
  term: {
378
- 'fields.id': { value: '4ef2760a-083a-466b-b761-667856aeb5ee' }
287
+ 'fields.id': {
288
+ value:
289
+ '4ef2760a-083a-466b-b761-667856aeb5ee'
290
+ }
379
291
  }
380
292
  },
381
293
  {
@@ -384,14 +296,16 @@ describe('projectPipeline', function () {
384
296
  {
385
297
  match: {
386
298
  'fields.text.analyzed': {
387
- query: params.search,
299
+ query:
300
+ '41853 69 SER-69 allan DoNALD Vikram RalPH',
388
301
  operator: 'and'
389
302
  }
390
303
  }
391
304
  },
392
305
  {
393
306
  match_phrase_prefix: {
394
- 'fields.text.analyzed': params.search
307
+ 'fields.text.analyzed':
308
+ '41853 69 SER-69 allan DoNALD Vikram RalPH'
395
309
  }
396
310
  }
397
311
  ]