@go-mailer/jarvis 4.0.4 → 4.1.0
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/lib/query.js +14 -14
- package/package.json +1 -1
package/lib/query.js
CHANGED
|
@@ -3,9 +3,9 @@ const buildQuery = (options) => {
|
|
|
3
3
|
const fields_to_return = options.return_only ? buildReturnFieldsString(options.return_only) : ''
|
|
4
4
|
const count = options.count || false
|
|
5
5
|
const group_by = options.group_by || null
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
let seek_conditions = {}
|
|
8
|
-
if (options.bool){
|
|
8
|
+
if (options.bool) {
|
|
9
9
|
seek_conditions = {
|
|
10
10
|
...seek_conditions,
|
|
11
11
|
...buildBooleanQuery(options.bool || '')
|
|
@@ -13,7 +13,7 @@ const buildQuery = (options) => {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (options.exists) {
|
|
16
|
-
seek_conditions = {
|
|
16
|
+
seek_conditions = {
|
|
17
17
|
...seek_conditions,
|
|
18
18
|
...buildExistsQuery(options.exists || '')
|
|
19
19
|
}
|
|
@@ -107,21 +107,21 @@ const buildExistsQuery = (value) => {
|
|
|
107
107
|
const buildInQuery = (value) => {
|
|
108
108
|
const values = value.split(':')
|
|
109
109
|
return {
|
|
110
|
-
$in: [...values]
|
|
110
|
+
$in: [...values].map(val => isNaN(val) ? val : Number(val))
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
const buildNorQuery = (value) => {
|
|
115
115
|
const values = value.split('!')
|
|
116
116
|
return {
|
|
117
|
-
$nin: [...values.slice(1)]
|
|
117
|
+
$nin: [...values.slice(1)].map(val => isNaN(val) ? val : Number(val))
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
const buildOrQuery = (value) => {
|
|
122
122
|
const values = value.split(',')
|
|
123
123
|
return {
|
|
124
|
-
$in: [...values]
|
|
124
|
+
$in: [...values].map(val => isNaN(val) ? val : Number(val))
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -175,8 +175,8 @@ const generateGroupPipeline = ({ group_by, seek_conditions, sort_condition, fiel
|
|
|
175
175
|
pipeline.push({
|
|
176
176
|
$match: { ...seek_conditions }
|
|
177
177
|
})
|
|
178
|
-
|
|
179
|
-
if (sort_condition){
|
|
178
|
+
|
|
179
|
+
if (sort_condition) {
|
|
180
180
|
const sort_options = sort_condition.split(' ').reduce((sac, condition) => {
|
|
181
181
|
let key = condition
|
|
182
182
|
let value = 1
|
|
@@ -184,7 +184,7 @@ const generateGroupPipeline = ({ group_by, seek_conditions, sort_condition, fiel
|
|
|
184
184
|
key = key.split('-')[1]
|
|
185
185
|
value = -1
|
|
186
186
|
}
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
return { ...sac, [key]: value }
|
|
189
189
|
}, {})
|
|
190
190
|
|
|
@@ -192,18 +192,18 @@ const generateGroupPipeline = ({ group_by, seek_conditions, sort_condition, fiel
|
|
|
192
192
|
$sort: { ...sort_options }
|
|
193
193
|
})
|
|
194
194
|
}
|
|
195
|
-
|
|
196
|
-
if (fields_to_return){
|
|
195
|
+
|
|
196
|
+
if (fields_to_return) {
|
|
197
197
|
const projection_options = fields_to_return.split(' ').reduce((sac, condition) => ({ ...sac, [condition]: 1 }), {})
|
|
198
198
|
|
|
199
199
|
pipeline.push({
|
|
200
200
|
$project: { ...projection_options }
|
|
201
201
|
})
|
|
202
202
|
}
|
|
203
|
-
|
|
203
|
+
|
|
204
204
|
pipeline.push({
|
|
205
205
|
$group: {
|
|
206
|
-
_id: { group_field: `$${group_field}`}
|
|
206
|
+
_id: { group_field: `$${group_field}` }
|
|
207
207
|
}
|
|
208
208
|
})
|
|
209
209
|
|
|
@@ -212,7 +212,7 @@ const generateGroupPipeline = ({ group_by, seek_conditions, sort_condition, fiel
|
|
|
212
212
|
$count: "size"
|
|
213
213
|
})
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
|
|
216
216
|
return pipeline
|
|
217
217
|
}
|
|
218
218
|
|