@outliant/sunrise-utils 1.0.5 → 1.0.6

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/.eslintrc CHANGED
@@ -42,7 +42,25 @@
42
42
  "import/no-extraneous-dependencies": "off",
43
43
  "no-shadow": "off",
44
44
  "no-else-return": "off",
45
- "no-restricted-globals": "off"
45
+ "no-restricted-globals": "off",
46
+ "semi": ["error", "always"],
47
+ "quote-props": ["error", "as-needed"],
48
+ "space-infix-ops": "error",
49
+ "object-curly-spacing": ["error", "always"],
50
+ "indent": [
51
+ "error",
52
+ 2,
53
+ {
54
+ "SwitchCase": 1
55
+ }
56
+ ],
57
+ "no-multiple-empty-lines": [
58
+ "error",
59
+ {
60
+ "max": 1,
61
+ "maxEOF": 0
62
+ }
63
+ ]
46
64
  },
47
65
  "parser": "@babel/eslint-parser",
48
66
  "parserOptions": {
package/CHANGELOG.md CHANGED
@@ -4,8 +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.0.6](https://github.com/outliant/sunrise-utils/compare/1.0.5...1.0.6)
8
+
9
+ - Task/string contains filters #860pq6e4d [`#2`](https://github.com/outliant/sunrise-utils/pull/2)
10
+ - chore: string contains filters [`2d80b31`](https://github.com/outliant/sunrise-utils/commit/2d80b31ac08ff5c1710373ccaae7c641333b5557)
11
+ - chore: add contains any/none filters [`eeec3bd`](https://github.com/outliant/sunrise-utils/commit/eeec3bdbce07ce6a9a782db3953c6926bfd24e4d)
12
+ - chore: revert pushes to main [`21cba44`](https://github.com/outliant/sunrise-utils/commit/21cba44219188192dc806fed59df2bdab1b63e88)
13
+
7
14
  #### [1.0.5](https://github.com/outliant/sunrise-utils/compare/1.0.4...1.0.5)
8
15
 
16
+ > 7 March 2023
17
+
18
+ - chore(release): 1.0.5 [`51f1f27`](https://github.com/outliant/sunrise-utils/commit/51f1f2766ad028f6769ed43625dd6b7eb977c4de)
9
19
  - chore: update custom sorting to be prepended on the list [`6d8c7e3`](https://github.com/outliant/sunrise-utils/commit/6d8c7e3f665fad6203b700fb4a104a8670572cb0)
10
20
 
11
21
  #### [1.0.4](https://github.com/outliant/sunrise-utils/compare/1.0.3...1.0.4)
@@ -1,8 +1,33 @@
1
1
  const moment = require('moment');
2
2
  const { escapeElasticQuery } = require('../es');
3
3
 
4
+ function getContainsMappingValue (filter) {
5
+ if (['text', 'textarea'].includes(filter.field_type)) {
6
+ return {
7
+ bool: {
8
+ must: [
9
+ {
10
+ match: {
11
+ [`fields.text.analyzed`]: {
12
+ query: filter.value,
13
+ operator: 'and'
14
+ }
15
+ }
16
+ }
17
+ ]
18
+ }
19
+ };
20
+ }
21
+
22
+ return {};
23
+ }
24
+
4
25
  module.exports = (filter) => {
5
26
  switch (filter.condition) {
27
+ case 'contains_any':
28
+ return module.exports.containsAny(filter);
29
+ case 'contains_none':
30
+ return module.exports.containsNone(filter);
6
31
  case 'is_empty':
7
32
  return module.exports.isEmpty(filter);
8
33
  case 'is_not_empty':
@@ -30,6 +55,94 @@ module.exports = (filter) => {
30
55
  }
31
56
  };
32
57
 
58
+ module.exports.containsAny = (filter) => {
59
+ if (!!filter.field_id) {
60
+ const mapping = getContainsMappingValue(filter);
61
+
62
+ if (!mapping) {
63
+ return null;
64
+ }
65
+
66
+ return {
67
+ bool: {
68
+ must: [
69
+ {
70
+ nested: {
71
+ path: 'fields',
72
+ query: {
73
+ bool: {
74
+ must: [
75
+ {
76
+ term: {
77
+ 'fields.id': {
78
+ value: filter.field_id
79
+ }
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ }
85
+ }
86
+ },
87
+ {
88
+ nested: {
89
+ path: 'fields',
90
+ query: mapping
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ };
96
+ }
97
+
98
+ return null;
99
+ };
100
+
101
+ module.exports.containsNone = (filter) => {
102
+ if (!!filter.field_id) {
103
+ const mapping = getContainsMappingValue(filter);
104
+
105
+ if (!mapping) {
106
+ return null;
107
+ }
108
+
109
+ return {
110
+ bool: {
111
+ must: [
112
+ {
113
+ nested: {
114
+ path: 'fields',
115
+ query: {
116
+ bool: {
117
+ must: [
118
+ {
119
+ term: {
120
+ 'fields.id': {
121
+ value: filter.field_id
122
+ }
123
+ }
124
+ }
125
+ ]
126
+ }
127
+ }
128
+ }
129
+ }
130
+ ],
131
+ must_not: [
132
+ {
133
+ nested: {
134
+ path: 'fields',
135
+ query: mapping
136
+ }
137
+ }
138
+ ]
139
+ }
140
+ };
141
+ }
142
+
143
+ return null;
144
+ };
145
+
33
146
  module.exports.isAnyOf = (filter) => {
34
147
  let value = filter.value;
35
148
 
@@ -2,6 +2,10 @@ const moment = require('moment');
2
2
 
3
3
  module.exports = (filter) => {
4
4
  switch (filter.condition) {
5
+ case 'contains_any':
6
+ return module.exports.containsAny(filter);
7
+ case 'contains_none':
8
+ return module.exports.containsNone(filter);
5
9
  case 'is_empty':
6
10
  return module.exports.isEmpty(filter);
7
11
  case 'is_any_of':
@@ -29,6 +33,63 @@ module.exports = (filter) => {
29
33
  }
30
34
  };
31
35
 
36
+
37
+ module.exports.containsAny = (filter) => {
38
+ /**
39
+ * Field type is for custom columns
40
+ */
41
+ const type = filter.field_type || filter.type;
42
+
43
+ if (['text', 'textarea'].includes(type)) {
44
+ const value = String(filter.value || '').split(';');
45
+
46
+ return {
47
+ bool: {
48
+ should: value.map(val => {
49
+ return {
50
+ match: {
51
+ [filter.type]: {
52
+ query: val,
53
+ operator: 'and'
54
+ }
55
+ }
56
+ };
57
+ })
58
+ }
59
+ };
60
+ }
61
+
62
+ return null;
63
+ };
64
+
65
+ module.exports.containsNone = (filter) => {
66
+ /**
67
+ * Field type is for custom columns
68
+ */
69
+ const type = filter.field_type || filter.type;
70
+
71
+ if (['text', 'textarea'].includes(type)) {
72
+ const value = String(filter.value || '').split(';');
73
+
74
+ return {
75
+ bool: {
76
+ must_not: value.map(val => {
77
+ return {
78
+ match: {
79
+ [filter.type]: {
80
+ query: val,
81
+ operator: 'and'
82
+ }
83
+ }
84
+ };
85
+ })
86
+ }
87
+ };
88
+ }
89
+
90
+ return null;
91
+ };
92
+
32
93
  module.exports.isAnyOf = (filter) => {
33
94
  let value = filter.value;
34
95
 
@@ -19,6 +19,14 @@ module.exports.conditions = {
19
19
  {
20
20
  label: 'Is any of',
21
21
  value: 'is_any_of'
22
+ },
23
+ {
24
+ label: 'Contains Any',
25
+ value: 'contains_any'
26
+ },
27
+ {
28
+ label: 'Contains None',
29
+ value: 'contains_none'
22
30
  }
23
31
  ],
24
32
  textarea: [
@@ -41,6 +49,14 @@ module.exports.conditions = {
41
49
  {
42
50
  label: 'Is any of',
43
51
  value: 'is_any_of'
52
+ },
53
+ {
54
+ label: 'Contains Any',
55
+ value: 'contains_any'
56
+ },
57
+ {
58
+ label: 'Contains None',
59
+ value: 'contains_none'
44
60
  }
45
61
  ],
46
62
  number: [
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.0.5",
4
+ "version": "1.0.6",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",