@outliant/sunrise-utils 1.1.28 → 1.1.31

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,10 +4,28 @@ 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.31](https://github.com/outliant/sunrise-utils/compare/1.1.29...1.1.31)
8
+
9
+ - Feature: Added Greater than N days ago filter #86b09hc0u [`#40`](https://github.com/outliant/sunrise-utils/pull/40)
10
+ - feature: Added Greater than N days ago filter #86b09hc0u [`7c917aa`](https://github.com/outliant/sunrise-utils/commit/7c917aa02896b008114aa1791eee4598ab115bdb)
11
+ - chore(release): 1.1.30 [`d738803`](https://github.com/outliant/sunrise-utils/commit/d738803831b98a9dca0f1b65c37943ed64911f24)
12
+ - chore(release): 1.1.30 [`ba31d9b`](https://github.com/outliant/sunrise-utils/commit/ba31d9b3d14596fe4d632dc0a7989622ede49ec3)
13
+
14
+ #### [1.1.29](https://github.com/outliant/sunrise-utils/compare/1.1.28...1.1.29)
15
+
16
+ > 6 June 2024
17
+
18
+ - chore: fix task field date filter #86b0j0q70 [`#38`](https://github.com/outliant/sunrise-utils/pull/38)
19
+ - chore: update task field date filter #86b0j0q70 [`3e806ba`](https://github.com/outliant/sunrise-utils/commit/3e806bac4a3144a9aa77ade67f980e6b583759c2)
20
+ - chore(release): 1.1.29 [`4ccbc43`](https://github.com/outliant/sunrise-utils/commit/4ccbc43eb40174c643b03478ec8bd7c2482b35d7)
21
+
7
22
  #### [1.1.28](https://github.com/outliant/sunrise-utils/compare/1.1.27...1.1.28)
8
23
 
24
+ > 4 April 2024
25
+
9
26
  - task starred column #86azquc2z [`#36`](https://github.com/outliant/sunrise-utils/pull/36)
10
27
  - banners name and options update #85ztcymgr [`#37`](https://github.com/outliant/sunrise-utils/pull/37)
28
+ - chore(release): 1.1.28 [`980137b`](https://github.com/outliant/sunrise-utils/commit/980137bef447c8c0fac3b9a116bc72c972bc13fd)
11
29
  - starredTaskIds parameter default value [`d1f69b5`](https://github.com/outliant/sunrise-utils/commit/d1f69b59611dc6b31d7c68a43e18b2920ea46c27)
12
30
 
13
31
  #### [1.1.27](https://github.com/outliant/sunrise-utils/compare/1.1.26...1.1.27)
@@ -66,6 +66,8 @@ module.exports = (filter) => {
66
66
  return module.exports.nextNDays(filter);
67
67
  case 'last_n_days':
68
68
  return module.exports.lastNDays(filter);
69
+ case 'greater_n_days_ago':
70
+ return module.exports.greaterNDaysAgo(filter);
69
71
  default:
70
72
  return null;
71
73
  }
@@ -610,6 +612,50 @@ module.exports.lastNDays = (filter) => {
610
612
  return null;
611
613
  };
612
614
 
615
+ module.exports.greaterNDaysAgo = (filter) => {
616
+ if (!filter.field_id || isNaN(filter.value)) {
617
+ return null;
618
+ }
619
+
620
+ const greaterNDaysAgo = moment()
621
+ .subtract(filter.value, 'd')
622
+ .endOf('day');
623
+
624
+ const res = {
625
+ bool: {
626
+ must: [
627
+ {
628
+ nested: {
629
+ path: 'fields',
630
+ query: {
631
+ bool: {
632
+ must: [
633
+ {
634
+ term: {
635
+ 'fields.id': {
636
+ value: filter.field_id
637
+ }
638
+ }
639
+ },
640
+ {
641
+ range: {
642
+ 'fields.number': {
643
+ lt: greaterNDaysAgo.valueOf()
644
+ }
645
+ }
646
+ }
647
+ ]
648
+ }
649
+ }
650
+ }
651
+ }
652
+ ]
653
+ }
654
+ };
655
+
656
+ return res;
657
+ }
658
+
613
659
  module.exports.isBeforeIncludeParam = (filter) => {
614
660
  if (!!filter.field_id) {
615
661
  let param;
@@ -26,6 +26,8 @@ module.exports = (filter) => {
26
26
  return module.exports.nextNDays(filter);
27
27
  case 'last_n_days':
28
28
  return module.exports.lastNDays(filter);
29
+ case 'greater_n_days_ago':
30
+ return module.exports.greaterNDaysAgo(filter);
29
31
  case 'is_empty':
30
32
  return module.exports.isEmpty(filter);
31
33
  case 'is_not_empty':
@@ -315,6 +317,28 @@ module.exports.lastNDays = (filter) => {
315
317
  return res;
316
318
  };
317
319
 
320
+ module.exports.greaterNDaysAgo = (filter) => {
321
+ if (!filter.type || isNaN(filter.value)) {
322
+ return null;
323
+ }
324
+
325
+ const greaterNDaysAgo = moment().subtract(filter.value, 'd').endOf('day');
326
+
327
+ return {
328
+ bool: {
329
+ must: [
330
+ {
331
+ range: {
332
+ [filter.type]: {
333
+ lt: greaterNDaysAgo.valueOf()
334
+ }
335
+ }
336
+ }
337
+ ]
338
+ }
339
+ };
340
+ };
341
+
318
342
  module.exports.isBetween = (filter) => {
319
343
  if (!filter.type) {
320
344
  return null;
@@ -16,6 +16,9 @@ module.exports = (filter) => {
16
16
  case 'is_not_empty':
17
17
  return module.exports.isNotEmpty(filter);
18
18
  case 'is_equal':
19
+ if (filter.type === 'ready_at') {
20
+ return module.exports.isReadyAt(filter);
21
+ }
19
22
  return module.exports.isEqual(filter);
20
23
  case 'not_equal':
21
24
  return module.exports.isNotEqual(filter);
@@ -40,6 +43,8 @@ module.exports = (filter) => {
40
43
  return module.exports.nextNDays(filter);
41
44
  case 'last_n_days':
42
45
  return module.exports.lastNDays(filter);
46
+ case 'greater_n_days_ago':
47
+ return module.exports.greaterNDaysAgo(filter);
43
48
  default:
44
49
  return null;
45
50
  }
@@ -297,6 +302,51 @@ module.exports.isEqual = (filter) => {
297
302
  };
298
303
  };
299
304
 
305
+ module.exports.isReadyAt = (filter) => {
306
+ const startOfDay = moment(filter.value).startOf('day').valueOf();
307
+ const endOfDay = moment(filter.value).endOf('day').valueOf();
308
+
309
+ return {
310
+ script: {
311
+ script: {
312
+ source: `
313
+ try {
314
+ def filterType = params.filterType;
315
+ def taskFilter = doc[filterType];
316
+
317
+ if (taskFilter.size() == 0) {
318
+ return false;
319
+ }
320
+
321
+ long startOfDay = params.startOfDay;
322
+ long endOfDay = params.endOfDay;
323
+
324
+ if (
325
+ filterType == 'ready_at' &&
326
+ doc['is_complete'].size() != 0 &&
327
+ doc['is_complete'].value == true &&
328
+ doc['completed_at'].size() != 0
329
+ ) {
330
+ long completedAt = doc['completed_at'].value.millis;
331
+ return completedAt >= startOfDay && completedAt <= endOfDay;
332
+ } else {
333
+ long taskFilterValue = taskFilter.value.millis;
334
+ return taskFilterValue >= startOfDay && taskFilterValue <= endOfDay;
335
+ }
336
+ } catch(Exception err){
337
+ return false;
338
+ }`,
339
+ lang: 'painless',
340
+ params: {
341
+ startOfDay,
342
+ endOfDay,
343
+ filterType: filter.type
344
+ }
345
+ }
346
+ }
347
+ };
348
+ };
349
+
300
350
  module.exports.isBefore = (filter) => {
301
351
  let param;
302
352
 
@@ -367,6 +417,20 @@ module.exports.lastNDays = (filter) => {
367
417
  };
368
418
  };
369
419
 
420
+ module.exports.greaterNDaysAgo = (filter) => {
421
+ if (isNaN(filter.value)) {
422
+ return null;
423
+ }
424
+
425
+ return {
426
+ range: {
427
+ [filter.type]: {
428
+ lt: `now/d-${filter.value}d`
429
+ }
430
+ }
431
+ };
432
+ };
433
+
370
434
  module.exports.isBeforeIncludeParam = (filter) => {
371
435
  let param;
372
436
 
@@ -189,6 +189,10 @@ module.exports.conditions = {
189
189
  {
190
190
  label: 'In The Last N Days',
191
191
  value: 'last_n_days'
192
+ },
193
+ {
194
+ label: 'Greater than N Days Ago',
195
+ value: 'greater_n_days_ago'
192
196
  }
193
197
  ],
194
198
  user_select: [
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.28",
4
+ "version": "1.1.31",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",
@@ -1236,6 +1236,29 @@ describe('projectFilter/projectFilter', () => {
1236
1236
  }
1237
1237
  }
1238
1238
  },
1239
+ {
1240
+ input: {
1241
+ condition: 'greater_n_days_ago',
1242
+ field_id: '5a681cb0-0682-48a8-875f-a525c795d398',
1243
+ type: 'created_at',
1244
+ field_type: 'date',
1245
+ value: 4,
1246
+ second_value: ''
1247
+ },
1248
+ output: {
1249
+ bool: {
1250
+ must: [
1251
+ {
1252
+ range: {
1253
+ created_at: {
1254
+ lt: moment().subtract(4, 'd').endOf('day').valueOf()
1255
+ }
1256
+ }
1257
+ }
1258
+ ]
1259
+ }
1260
+ }
1261
+ },
1239
1262
  {
1240
1263
  input: {
1241
1264
  condition: 'is_empty',
@@ -435,6 +435,53 @@ describe('taskFieldFilter', function () {
435
435
  second_value: ''
436
436
  },
437
437
  output: null
438
+ },
439
+ {
440
+ input: {
441
+ condition: 'is_equal',
442
+ field_id: '',
443
+ type: 'ready_at',
444
+ field_type: 'date',
445
+ value: 1675296000000,
446
+ second_value: ''
447
+ },
448
+ output: {
449
+ script:{
450
+ script: {
451
+ source: "\n try {\n def filterType = params.filterType;\n def taskFilter = doc[filterType];\n\n if (taskFilter.size() == 0) {\n return false;\n }\n\n long startOfDay = params.startOfDay;\n long endOfDay = params.endOfDay;\n\n if (\n filterType == 'ready_at' &&\n doc['is_complete'].size() != 0 &&\n doc['is_complete'].value == true &&\n doc['completed_at'].size() != 0\n ) {\n long completedAt = doc['completed_at'].value.millis;\n return completedAt >= startOfDay && completedAt <= endOfDay;\n } else {\n long taskFilterValue = taskFilter.value.millis;\n return taskFilterValue >= startOfDay && taskFilterValue <= endOfDay;\n }\n } catch(Exception err){\n return false;\n }",
452
+ lang: 'painless',
453
+ params: {
454
+ startOfDay: 1675267200000,
455
+ endOfDay: 1675353599999,
456
+ filterType: 'ready_at'
457
+ }
458
+ }
459
+ }
460
+ }
461
+ },
462
+ {
463
+ input: {
464
+ condition: 'greater_n_days_ago',
465
+ field_id: '',
466
+ type: 'created_at',
467
+ field_type: 'number',
468
+ value: '30',
469
+ second_value: ''
470
+ },
471
+ output: {
472
+ range: {
473
+ created_at: {
474
+ lt: 'now/d-30d'
475
+ }
476
+ }
477
+ }
478
+ },
479
+ {
480
+ input: {
481
+ type: 'greater_n_days_ago',
482
+ value: 'not_a_number'
483
+ },
484
+ output: null
438
485
  }
439
486
  ];
440
487