@outliant/sunrise-utils 1.1.6 → 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,9 +4,18 @@ 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
+
7
13
  #### [1.1.6](https://github.com/outliant/sunrise-utils/compare/1.1.5...1.1.6)
8
14
 
15
+ > 20 September 2023
16
+
9
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)
10
19
 
11
20
  #### [1.1.5](https://github.com/outliant/sunrise-utils/compare/1.1.4...1.1.5)
12
21
 
@@ -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.6",
4
+ "version": "1.1.7",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",