@outliant/sunrise-utils 1.1.29 → 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 +10 -0
- package/helpers/projectFilter/projectFieldFilter.js +46 -0
- package/helpers/projectFilter/projectFilter.js +24 -0
- package/helpers/taskFilter/taskFieldFilter.js +16 -0
- package/lib/fieldConditions.js +4 -0
- package/package.json +1 -1
- package/test/helpers/projectFilter/projectFieldFilter.spec.js +23 -0
- package/test/helpers/taskFilter/taskFieldFilter.spec.js +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,10 +4,20 @@ 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
|
+
|
|
7
14
|
#### [1.1.29](https://github.com/outliant/sunrise-utils/compare/1.1.28...1.1.29)
|
|
8
15
|
|
|
16
|
+
> 6 June 2024
|
|
17
|
+
|
|
9
18
|
- chore: fix task field date filter #86b0j0q70 [`#38`](https://github.com/outliant/sunrise-utils/pull/38)
|
|
10
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)
|
|
11
21
|
|
|
12
22
|
#### [1.1.28](https://github.com/outliant/sunrise-utils/compare/1.1.27...1.1.28)
|
|
13
23
|
|
|
@@ -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;
|
|
@@ -43,6 +43,8 @@ module.exports = (filter) => {
|
|
|
43
43
|
return module.exports.nextNDays(filter);
|
|
44
44
|
case 'last_n_days':
|
|
45
45
|
return module.exports.lastNDays(filter);
|
|
46
|
+
case 'greater_n_days_ago':
|
|
47
|
+
return module.exports.greaterNDaysAgo(filter);
|
|
46
48
|
default:
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
@@ -415,6 +417,20 @@ module.exports.lastNDays = (filter) => {
|
|
|
415
417
|
};
|
|
416
418
|
};
|
|
417
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
|
+
|
|
418
434
|
module.exports.isBeforeIncludeParam = (filter) => {
|
|
419
435
|
let param;
|
|
420
436
|
|
package/lib/fieldConditions.js
CHANGED
package/package.json
CHANGED
|
@@ -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',
|
|
@@ -458,6 +458,30 @@ describe('taskFieldFilter', function () {
|
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
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
|
|
461
485
|
}
|
|
462
486
|
];
|
|
463
487
|
|