@outliant/sunrise-utils 1.1.5 → 1.1.7

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.1.7](https://github.com/outliant/sunrise-utils/compare/1.1.6...1.1.7)
8
+
9
+ - chore: update users pipeline [`#11`](https://github.com/outliant/sunrise-utils/pull/11)
10
+ - chore: remove map [`6c6972b`](https://github.com/outliant/sunrise-utils/commit/6c6972b89bd60cb44bb48613ad206b785e1f1771)
11
+ - chore: use buildProjectFilter [`0cae6ce`](https://github.com/outliant/sunrise-utils/commit/0cae6ce4ca13dc56b98e9b98a6c6cff9881824c2)
12
+
13
+ #### [1.1.6](https://github.com/outliant/sunrise-utils/compare/1.1.5...1.1.6)
14
+
15
+ > 20 September 2023
16
+
17
+ - chore: change logic for last/next n days filter [`#10`](https://github.com/outliant/sunrise-utils/pull/10)
18
+ - chore(release): 1.1.6 [`1158429`](https://github.com/outliant/sunrise-utils/commit/1158429285eeb1f80d2dd7c55bd21b1291248469)
19
+
7
20
  #### [1.1.5](https://github.com/outliant/sunrise-utils/compare/1.1.4...1.1.5)
8
21
 
22
+ > 19 May 2023
23
+
9
24
  - Task/project banner #866a3c0ug [`#9`](https://github.com/outliant/sunrise-utils/pull/9)
10
25
  - chore: filter checkbox [`fb8d601`](https://github.com/outliant/sunrise-utils/commit/fb8d6015b1ee2092fc69b64d10b0a26b59958574)
11
26
  - chore: update spec [`bcbfd9a`](https://github.com/outliant/sunrise-utils/commit/bcbfd9ad5a21b412c160a85b05d63a43771bc084)
@@ -334,18 +334,11 @@ module.exports.nextNDays = (filter) => {
334
334
  return null;
335
335
  }
336
336
 
337
- const today = moment()
338
- .startOf('day');
339
-
340
- const nextNDays = moment()
341
- .add(filter.value, 'd')
342
- .endOf('day');
343
-
344
337
  return {
345
338
  range: {
346
339
  [filter.type]: {
347
- gt: today.valueOf(),
348
- lt: nextNDays.valueOf()
340
+ lt: `now/d+${filter.value}d`,
341
+ gt: 'now/d'
349
342
  }
350
343
  }
351
344
  };
@@ -356,18 +349,11 @@ module.exports.lastNDays = (filter) => {
356
349
  return null;
357
350
  }
358
351
 
359
- const today = moment()
360
- .startOf('day');
361
-
362
- const lastNDays = moment()
363
- .subtract(filter.value, 'd')
364
- .endOf('day');
365
-
366
352
  return {
367
353
  range: {
368
354
  [filter.type]: {
369
- lt: today.valueOf(),
370
- gt: lastNDays.valueOf()
355
+ gt: `now/d-${filter.value}d`,
356
+ lt: 'now/d'
371
357
  }
372
358
  }
373
359
  };
@@ -0,0 +1,77 @@
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
+ default:
8
+ return null;
9
+ }
10
+ };
11
+
12
+ module.exports.isEqual = (filter) => {
13
+ switch (filter.value) {
14
+ case 'active':
15
+ return {
16
+ bool: {
17
+ must: [
18
+ {
19
+ term: {
20
+ pending: false
21
+ }
22
+ },
23
+ {
24
+ term: {
25
+ disabled: false
26
+ }
27
+ }
28
+ ]
29
+ }
30
+ };
31
+ case 'pending':
32
+ return {
33
+ bool: {
34
+ must: [
35
+ {
36
+ term: {
37
+ pending: true
38
+ }
39
+ },
40
+ {
41
+ term: {
42
+ disabled: false
43
+ }
44
+ }
45
+ ]
46
+ }
47
+ };
48
+ case 'disabled':
49
+ return {
50
+ bool: {
51
+ must: [
52
+ {
53
+ term: {
54
+ disabled: true
55
+ }
56
+ }
57
+ ]
58
+ }
59
+ };
60
+ default:
61
+ return null;
62
+ }
63
+ };
64
+
65
+ module.exports.isNotEqual = (filter) => {
66
+ const equalFilter = module.exports.isEqual(filter);
67
+
68
+ if (equalFilter) {
69
+ return {
70
+ bool: {
71
+ must_not: equalFilter
72
+ }
73
+ };
74
+ }
75
+
76
+ return null;
77
+ };
@@ -0,0 +1,27 @@
1
+ const status = (order) => {
2
+ return {
3
+ _script: {
4
+ type: 'string',
5
+ order,
6
+ script: {
7
+ lang: 'painless',
8
+ source: `
9
+ def isPending = doc['pending'].value;
10
+ def isDisabled = doc['disabled'].value;
11
+
12
+ if (isPending) {
13
+ return 'pending';
14
+ } else if (isDisabled) {
15
+ return 'disabled';
16
+ } else {
17
+ return 'active';
18
+ }
19
+ `
20
+ }
21
+ }
22
+ };
23
+ };
24
+
25
+ module.exports = {
26
+ status,
27
+ };
package/index.js CHANGED
@@ -2,10 +2,12 @@ const log = require('./lib/logger');
2
2
  const fieldConditions = require('./lib/fieldConditions');
3
3
  const taskPipeline = require('./lib/taskPipeline');
4
4
  const projectPipeline = require('./lib/projectPipeline');
5
+ const usersPipeline = require('./lib/usersPipeline');
5
6
 
6
7
  module.exports = {
7
8
  log,
8
9
  fieldConditions,
9
10
  taskPipeline,
10
- projectPipeline
11
+ projectPipeline,
12
+ usersPipeline
11
13
  };
@@ -0,0 +1,53 @@
1
+ const sortScript = require('../helpers/users/sortScript');
2
+ const buildProjectFilter = require('../helpers/projectFilter/projectFilter');
3
+
4
+ // customer filters
5
+ const buildStatusFilter = require('../helpers/users/filters/status');
6
+
7
+ class UsersPipeline {
8
+ buildFiltersQuery({ filters }) {
9
+ const mustQuery = [];
10
+
11
+ for (const filter of filters) {
12
+ switch (filter.type) {
13
+ case 'status':
14
+ mustQuery.push(buildStatusFilter(filter));
15
+ break;
16
+
17
+ default: {
18
+ const queryFilter = buildProjectFilter(filter);
19
+
20
+ if (queryFilter) {
21
+ mustQuery.push(queryFilter);
22
+ }
23
+ break;
24
+ }
25
+ }
26
+ }
27
+
28
+ return { bool: { must: mustQuery } };
29
+ }
30
+
31
+ buildSortScript ({ sorts }) {
32
+ const usersPipelineSorts = [];
33
+
34
+ sorts.forEach(sort => {
35
+ switch (sort.field) {
36
+ case 'status':
37
+ usersPipelineSorts.push(sortScript.status(sort.direction));
38
+ break;
39
+
40
+ default:
41
+ usersPipelineSorts.push({
42
+ [sort.field]: { order: sort.direction }
43
+ });
44
+ break;
45
+ }
46
+
47
+ });
48
+
49
+ return usersPipelineSorts;
50
+ }
51
+ }
52
+
53
+ module.exports = new UsersPipeline();
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.5",
4
+ "version": "1.1.7",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",