@outliant/sunrise-utils 1.1.16 → 1.1.18

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.18](https://github.com/outliant/sunrise-utils/compare/1.1.17...1.1.18)
8
+
9
+ - chore: update is_paused query filters #863hbxjkt [`#24`](https://github.com/outliant/sunrise-utils/pull/24)
10
+
11
+ #### [1.1.17](https://github.com/outliant/sunrise-utils/compare/1.1.16...1.1.17)
12
+
13
+ > 15 January 2024
14
+
15
+ - chore: update task status filter #863hbxjkt [`#23`](https://github.com/outliant/sunrise-utils/pull/23)
16
+ - chore: clean up is_paused filter #863hbxjkt [`f098a15`](https://github.com/outliant/sunrise-utils/commit/f098a15636cc2bb8fcd1c2bfc3fb9f4ceec5fc89)
17
+ - chore(release): 1.1.17 [`a796e59`](https://github.com/outliant/sunrise-utils/commit/a796e594a343f41ceb7941607f43ed95c894d2e5)
18
+
7
19
  #### [1.1.16](https://github.com/outliant/sunrise-utils/compare/1.1.15...1.1.16)
8
20
 
21
+ > 13 December 2023
22
+
9
23
  - chore: update is none of filter #85ztm47dj [`#22`](https://github.com/outliant/sunrise-utils/pull/22)
24
+ - chore(release): 1.1.16 [`e322032`](https://github.com/outliant/sunrise-utils/commit/e32203205b74ae0e079612ab842451b210263051)
10
25
 
11
26
  #### [1.1.15](https://github.com/outliant/sunrise-utils/compare/1.1.14...1.1.15)
12
27
 
@@ -34,6 +34,7 @@ module.exports.defaultCustomColumns = [
34
34
  field_type: 'select'
35
35
  },
36
36
  {
37
+ validate: (validator) => validator && validator.isCommercial(),
37
38
  name: 'Is Paused',
38
39
  value: 'is_paused',
39
40
  type: 'is_paused',
@@ -32,6 +32,11 @@ module.exports.taskStatusOptions = [
32
32
  {
33
33
  label: 'Overdue',
34
34
  value: 'overdue'
35
+ },
36
+ {
37
+ validate: (validator) => validator && validator.isCommercial(),
38
+ label: 'Paused',
39
+ value: 'paused'
35
40
  }
36
41
  ];
37
42
 
@@ -123,6 +128,7 @@ module.exports.defaultCustomColumns = [
123
128
  ]
124
129
  },
125
130
  {
131
+ validate: (validator) => validator && validator.isCommercial(),
126
132
  name: 'Is Paused',
127
133
  value: 'is_paused',
128
134
  type: 'is_paused',
@@ -141,6 +141,18 @@ module.exports.isEqual = (filter) => {
141
141
  ]
142
142
  }
143
143
  };
144
+ case 'paused':
145
+ return {
146
+ bool: {
147
+ must: [
148
+ {
149
+ term: {
150
+ is_paused: true
151
+ }
152
+ }
153
+ ]
154
+ }
155
+ };
144
156
  default:
145
157
  return null;
146
158
  }
package/index.d.ts CHANGED
@@ -69,6 +69,11 @@ declare namespace Utils {
69
69
  ): any;
70
70
  export function buildSortScript(query?: Query, customSort?: any[]): any;
71
71
  }
72
+
73
+ namespace queries {
74
+ export function getIsPausedQuery(): any;
75
+ export function getNotIsPausedQuery(): any;
76
+ }
72
77
  }
73
78
 
74
79
  export = Utils;
package/index.js CHANGED
@@ -3,11 +3,13 @@ const fieldConditions = require('./lib/fieldConditions');
3
3
  const taskPipeline = require('./lib/taskPipeline');
4
4
  const projectPipeline = require('./lib/projectPipeline');
5
5
  const usersPipeline = require('./lib/usersPipeline');
6
+ const queries = require('./lib/queries');
6
7
 
7
8
  module.exports = {
8
9
  log,
9
10
  fieldConditions,
10
11
  taskPipeline,
11
12
  projectPipeline,
12
- usersPipeline
13
+ usersPipeline,
14
+ queries
13
15
  };
package/lib/queries.js ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Generates an Elasticsearch query for filtering based on 'is_paused' equals to 'true'.
3
+ *
4
+ * @returns {Object} - Elasticsearch query object.
5
+ */
6
+ module.exports.getIsPausedQuery = () => {
7
+ return {
8
+ bool: {
9
+ must: [
10
+ {
11
+ term: {
12
+ is_paused: true
13
+ }
14
+ }
15
+ ]
16
+ }
17
+ };
18
+ };
19
+
20
+ /**
21
+ * Generates an Elasticsearch query for filtering based on 'is_paused' equal to 'false' or doesn't exist.
22
+ *
23
+ * @returns {Object} - Elasticsearch query object.
24
+ */
25
+ module.exports.getNotIsPausedQuery = () => {
26
+ return {
27
+ bool: {
28
+ should: [
29
+ {
30
+ bool: {
31
+ must: [
32
+ {
33
+ exists: {
34
+ field: 'is_paused'
35
+ }
36
+ },
37
+ {
38
+ match: {
39
+ is_paused: false
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ },
45
+ {
46
+ bool: {
47
+ must_not: {
48
+ exists: {
49
+ field: 'is_paused'
50
+ }
51
+ }
52
+ }
53
+ }
54
+ ]
55
+ }
56
+ };
57
+ };
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.16",
4
+ "version": "1.1.18",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",
@@ -54,6 +54,23 @@ describe('taskFilter/statusFilter', function () {
54
54
  }
55
55
  }
56
56
  },
57
+ {
58
+ input: {
59
+ condition: 'is_equal',
60
+ field_id: '',
61
+ type: 'status',
62
+ field_type: 'select',
63
+ value: 'paused',
64
+ second_value: ''
65
+ },
66
+ output: {
67
+ bool: {
68
+ must: [
69
+ { term: { is_paused: true } }
70
+ ]
71
+ }
72
+ }
73
+ },
57
74
  {
58
75
  input: {
59
76
  condition: 'is_equal',
@@ -128,7 +145,7 @@ describe('taskFilter/statusFilter', function () {
128
145
  field_id: '',
129
146
  type: 'status',
130
147
  field_type: 'select',
131
- value: 'new;on_hold',
148
+ value: 'new;on_hold;paused',
132
149
  second_value: ''
133
150
  },
134
151
  output: {
@@ -142,7 +159,8 @@ describe('taskFilter/statusFilter', function () {
142
159
  ]
143
160
  }
144
161
  },
145
- { bool: { must: [{ term: { on_hold: true } }] } }
162
+ { bool: { must: [{ term: { on_hold: true } }] } },
163
+ { bool: { must: [{ term: { is_paused: true } }] } }
146
164
  ]
147
165
  }
148
166
  }
@@ -153,7 +171,33 @@ describe('taskFilter/statusFilter', function () {
153
171
  field_id: '',
154
172
  type: 'status',
155
173
  field_type: 'select',
156
- value: ['new', 'on_hold'],
174
+ value: 'new,on_hold,paused',
175
+ second_value: ''
176
+ },
177
+ output: {
178
+ bool: {
179
+ should: [
180
+ {
181
+ bool: {
182
+ must: [
183
+ { term: { is_ready: false } },
184
+ { term: { is_complete: false } }
185
+ ]
186
+ }
187
+ },
188
+ { bool: { must: [{ term: { on_hold: true } }] } },
189
+ { bool: { must: [{ term: { is_paused: true } }] } }
190
+ ]
191
+ }
192
+ }
193
+ },
194
+ {
195
+ input: {
196
+ condition: 'is_any_of',
197
+ field_id: '',
198
+ type: 'status',
199
+ field_type: 'select',
200
+ value: ['new', 'on_hold', 'paused'],
157
201
  second_value: ''
158
202
  },
159
203
  output: {
@@ -167,7 +211,8 @@ describe('taskFilter/statusFilter', function () {
167
211
  ]
168
212
  }
169
213
  },
170
- { bool: { must: [{ term: { on_hold: true } }] } }
214
+ { bool: { must: [{ term: { on_hold: true } }] } },
215
+ { bool: { must: [{ term: { is_paused: true } }] } }
171
216
  ]
172
217
  }
173
218
  }
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ /* eslint-env node, mocha */
4
+ const { expect } = require('chai');
5
+
6
+ // To test
7
+ const queries = require('../../lib/queries');
8
+
9
+ describe('queries', function () {
10
+ describe('getIsPausedQuery', () => {
11
+ it('should return an \'is_paused\' query', () => {
12
+ const output = queries.getIsPausedQuery();
13
+
14
+ expect(output).to.be.deep.equal({
15
+ bool: {
16
+ must: [
17
+ {
18
+ term: {
19
+ is_paused: true
20
+ }
21
+ }
22
+ ]
23
+ }
24
+ });
25
+ });
26
+ });
27
+
28
+ describe('getNotIsPausedQuery', () => {
29
+ it('should return a \'not is_paused\' query', () => {
30
+ const output = queries.getNotIsPausedQuery();
31
+
32
+ expect(output).to.be.deep.equal({
33
+ bool: {
34
+ should: [
35
+ {
36
+ bool: {
37
+ must: [
38
+ {
39
+ exists: {
40
+ field: 'is_paused'
41
+ }
42
+ },
43
+ {
44
+ match: {
45
+ is_paused: false
46
+ }
47
+ }
48
+ ]
49
+ }
50
+ },
51
+ {
52
+ bool: {
53
+ must_not: {
54
+ exists: {
55
+ field: 'is_paused'
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ]
61
+ }
62
+ });
63
+ });
64
+ });
65
+ });