@outliant/sunrise-utils 1.1.22 → 1.1.24

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,9 +4,24 @@ 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.1.24](https://github.com/outliant/sunrise-utils/compare/1.1.23...1.1.24)
8
+
9
+ - chore: fix task status filtering #86azhkzeb [`#32`](https://github.com/outliant/sunrise-utils/pull/32)
10
+ - chore: add due date sort script #86az9tt26 [`#33`](https://github.com/outliant/sunrise-utils/pull/33)
11
+
12
+ #### [1.1.23](https://github.com/outliant/sunrise-utils/compare/1.1.22...1.1.23)
13
+
14
+ > 28 February 2024
15
+
16
+ - chore: fix task pipeline last comment date filtering #86azcxk24 [`#29`](https://github.com/outliant/sunrise-utils/pull/29)
17
+ - chore(release): 1.1.23 [`b806236`](https://github.com/outliant/sunrise-utils/commit/b80623635b5eb5ddfe9566458fcb493de4daed7b)
18
+
7
19
  #### [1.1.22](https://github.com/outliant/sunrise-utils/compare/1.1.21...1.1.22)
8
20
 
21
+ > 27 February 2024
22
+
9
23
  - chore: update sticky filters migration sort rule #86azcbz94 [`#28`](https://github.com/outliant/sunrise-utils/pull/28)
24
+ - chore(release): 1.1.22 [`9383476`](https://github.com/outliant/sunrise-utils/commit/9383476cdd89b29a56fce8c2269b11f1eae7db3d)
10
25
 
11
26
  #### [1.1.21](https://github.com/outliant/sunrise-utils/compare/1.1.20...1.1.21)
12
27
 
@@ -284,6 +284,25 @@ module.exports.readyAt = (order) => {
284
284
  };
285
285
  };
286
286
 
287
+ module.exports.dueDate = (order) => {
288
+ return {
289
+ _script: {
290
+ type: 'number',
291
+ script: {
292
+ lang: 'painless',
293
+ source: `
294
+ if (!doc['due_date'].empty) {
295
+ return doc['due_date'].value.millis;
296
+ } else {
297
+ return -999999;
298
+ }
299
+ `
300
+ },
301
+ order
302
+ }
303
+ };
304
+ };
305
+
287
306
  module.exports.wasMarkedIncomplete = (order) => {
288
307
  return {
289
308
  _script: {
@@ -298,6 +298,11 @@ module.exports.buildTaskPipelineFilter = (filter) => {
298
298
  ...filter,
299
299
  type: 'ready_at'
300
300
  });
301
+ case 'last_comment_date':
302
+ return buildTaskFieldFilter({
303
+ ...filter,
304
+ type: 'last_comment_data.created_at'
305
+ });
301
306
  // Always expected as is_equal condition with array of task template ids
302
307
  case 'task_templates':
303
308
  let value = filter.value;
@@ -89,6 +89,26 @@ module.exports.isEqual = (filter) => {
89
89
  term: {
90
90
  is_complete: false
91
91
  }
92
+ },
93
+ {
94
+ bool: {
95
+ should: [
96
+ {
97
+ term: {
98
+ is_paused: false
99
+ }
100
+ },
101
+ {
102
+ bool: {
103
+ must_not: {
104
+ exists: {
105
+ field: 'is_paused'
106
+ }
107
+ }
108
+ }
109
+ }
110
+ ]
111
+ }
92
112
  }
93
113
  ]
94
114
  }
@@ -149,6 +149,10 @@ class TaskPipeline {
149
149
  taskPipelinesSort.push(sortScript.lastCommentDate(sort));
150
150
  break;
151
151
 
152
+ case s === 'due_date':
153
+ taskPipelinesSort.push(sortScript.dueDate(sort));
154
+ break;
155
+
152
156
  case isUuid(s):
153
157
  taskPipelinesSort.push(sortScript.projectFieldNumeric(sort, s));
154
158
  taskPipelinesSort.push(sortScript.projectFieldText(sort, s));
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.1.22",
4
+ "version": "1.1.24",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ /* eslint-env node, mocha */
4
+ const { expect } = require('chai');
5
+
6
+ // To test
7
+ const sortScript = require('../../helpers/sortScript');
8
+
9
+ describe('sortScript', function () {
10
+ describe('dueDate', function () {
11
+ const orders = ['desc', 'asc'];
12
+ for (const order of orders) {
13
+ it(`should handle \`${order}\` sort order`, () => {
14
+ const sort = sortScript.dueDate(order);
15
+ expect(sort).to.be.deep.equal({
16
+ _script: {
17
+ type: 'number',
18
+ script: {
19
+ lang: 'painless',
20
+ source: '\n' +
21
+ " if (!doc['due_date'].empty) {\n" +
22
+ " return doc['due_date'].value.millis;\n" +
23
+ ' } else {\n' +
24
+ ' return -999999;\n' +
25
+ ' }\n' +
26
+ ' '
27
+ },
28
+ order
29
+ }
30
+ });
31
+ });
32
+ }
33
+ });
34
+ });
@@ -19,7 +19,38 @@ describe('taskFilter', function () {
19
19
  });
20
20
  expect(filter).to.be.deep.equal({
21
21
  bool: {
22
- must: [{ term: { is_ready: true } }, { term: { is_complete: false } }]
22
+ must: [
23
+ {
24
+ term: {
25
+ is_ready: true
26
+ }
27
+ },
28
+ {
29
+ term: {
30
+ is_complete: false
31
+ }
32
+ },
33
+ {
34
+ bool: {
35
+ should: [
36
+ {
37
+ term: {
38
+ is_paused: false
39
+ }
40
+ },
41
+ {
42
+ bool: {
43
+ must_not: {
44
+ exists: {
45
+ field: 'is_paused'
46
+ }
47
+ }
48
+ }
49
+ }
50
+ ]
51
+ }
52
+ }
53
+ ]
23
54
  }
24
55
  });
25
56
  done();
@@ -357,5 +388,109 @@ describe('taskFilter', function () {
357
388
  });
358
389
  done();
359
390
  });
391
+
392
+ describe('last_comment_date', () => {
393
+ it('should handle `is_equal` filter', () => {
394
+ const filter = taskFilter.buildTaskPipelineFilter({
395
+ field_id: '',
396
+ field_type: 'date',
397
+ type: 'last_comment_date',
398
+ condition: 'is_equal',
399
+ value: 1704067200000,
400
+ second_value: null
401
+ });
402
+
403
+ expect(filter).to.be.deep.equal({
404
+ range: {
405
+ 'last_comment_data.created_at': {
406
+ gte: 1704038400000,
407
+ lte: 1704124799999
408
+ }
409
+ }
410
+ });
411
+ });
412
+
413
+ it('should handle `not_equal` filter', () => {
414
+ const filter = taskFilter.buildTaskPipelineFilter({
415
+ field_id: '',
416
+ field_type: 'date',
417
+ type: 'last_comment_date',
418
+ condition: 'not_equal',
419
+ value: 1704067200000,
420
+ second_value: null
421
+ });
422
+
423
+ expect(filter).to.be.deep.equal({
424
+ bool: {
425
+ must_not: {
426
+ range: {
427
+ 'last_comment_data.created_at': {
428
+ gte: 1704038400000,
429
+ lte: 1704124799999
430
+ }
431
+ }
432
+ }
433
+ }
434
+ });
435
+ });
436
+
437
+ it('should handle `after` filter', () => {
438
+ const filter = taskFilter.buildTaskPipelineFilter({
439
+ field_id: '',
440
+ field_type: 'date',
441
+ type: 'last_comment_date',
442
+ condition: 'after',
443
+ value: 1704067200000,
444
+ second_value: null
445
+ });
446
+
447
+ expect(filter).to.be.deep.equal({
448
+ range: {
449
+ 'last_comment_data.created_at': {
450
+ gt: 1704124799999
451
+ }
452
+ }
453
+ });
454
+ });
455
+
456
+ it('should handle `before` filter', () => {
457
+ const filter = taskFilter.buildTaskPipelineFilter({
458
+ field_id: '',
459
+ field_type: 'date',
460
+ type: 'last_comment_date',
461
+ condition: 'before',
462
+ value: 1704067200000,
463
+ second_value: null
464
+ });
465
+
466
+ expect(filter).to.be.deep.equal({
467
+ range: {
468
+ 'last_comment_data.created_at': {
469
+ lt: 1704038400000
470
+ }
471
+ }
472
+ });
473
+ });
474
+
475
+ it('should handle `between` filter', () => {
476
+ const filter = taskFilter.buildTaskPipelineFilter({
477
+ field_id: '',
478
+ field_type: 'date',
479
+ type: 'last_comment_date',
480
+ condition: 'between',
481
+ value: '01/19/2024',
482
+ second_value: '02/29/2024'
483
+ });
484
+
485
+ expect(filter).to.be.deep.equal({
486
+ range: {
487
+ 'last_comment_data.created_at': {
488
+ gte: 1705593600000,
489
+ lte: 1709222399999
490
+ }
491
+ }
492
+ });
493
+ });
494
+ });
360
495
  });
361
496
  });
@@ -31,7 +31,38 @@ describe('taskFilter/statusFilter', function () {
31
31
  },
32
32
  output: {
33
33
  bool: {
34
- must: [{ term: { is_ready: true } }, { term: { is_complete: false } }]
34
+ must: [
35
+ {
36
+ term: {
37
+ is_ready: true
38
+ }
39
+ },
40
+ {
41
+ term: {
42
+ is_complete: false
43
+ }
44
+ },
45
+ {
46
+ bool: {
47
+ should: [
48
+ {
49
+ term: {
50
+ is_paused: false
51
+ }
52
+ },
53
+ {
54
+ bool: {
55
+ must_not: {
56
+ exists: {
57
+ field: 'is_paused'
58
+ }
59
+ }
60
+ }
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ ]
35
66
  }
36
67
  }
37
68
  },
@@ -72,22 +72,80 @@ describe('taskPipeline', function () {
72
72
  expect(filter).to.deep.equal({
73
73
  bool: {
74
74
  must: [
75
- { term: { organization_id: { value: 'test-org' } } },
76
- { term: { department_id: { value: 'test-department' } } },
77
- { term: { project_id: { value: 'test-project' } } },
75
+ {
76
+ term: {
77
+ organization_id: {
78
+ value: 'test-org'
79
+ }
80
+ }
81
+ },
82
+ {
83
+ term: {
84
+ department_id: {
85
+ value: 'test-department'
86
+ }
87
+ }
88
+ },
89
+ {
90
+ term: {
91
+ project_id: {
92
+ value: 'test-project'
93
+ }
94
+ }
95
+ },
78
96
  {
79
97
  bool: {
80
98
  must: [
81
- { term: { is_ready: true } },
82
- { term: { is_complete: false } }
99
+ {
100
+ term: {
101
+ is_ready: true
102
+ }
103
+ },
104
+ {
105
+ term: {
106
+ is_complete: false
107
+ }
108
+ },
109
+ {
110
+ bool: {
111
+ should: [
112
+ {
113
+ term: {
114
+ is_paused: false
115
+ }
116
+ },
117
+ {
118
+ bool: {
119
+ must_not: {
120
+ exists: {
121
+ field: 'is_paused'
122
+ }
123
+ }
124
+ }
125
+ }
126
+ ]
127
+ }
128
+ }
83
129
  ]
84
130
  }
85
131
  },
86
132
  {
87
133
  bool: {
88
134
  should: [
89
- { term: { on_hold: false } },
90
- { bool: { must_not: { exists: { field: 'on_hold' } } } }
135
+ {
136
+ term: {
137
+ on_hold: false
138
+ }
139
+ },
140
+ {
141
+ bool: {
142
+ must_not: {
143
+ exists: {
144
+ field: 'on_hold'
145
+ }
146
+ }
147
+ }
148
+ }
91
149
  ]
92
150
  }
93
151
  }