@go-mailer/jarvis 3.2.11 → 3.3.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/README.md +16 -0
- package/lib/query.js +33 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -224,6 +224,22 @@ Keywords in request queries are used to prepare the following queries. Given the
|
|
|
224
224
|
```
|
|
225
225
|
GET https://go-mailer.com?group_by=age
|
|
226
226
|
```
|
|
227
|
+
7. **boolean**: To return items that match the query for boolean fields, the `bool` keyword is used. pre-pending the minus (-) signto the name of the field would evaluate that field to `false` and vice-versa.
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
GET https://go-mailer.com?bool=age,-name
|
|
231
|
+
|
|
232
|
+
// evaluates to:
|
|
233
|
+
{ age: true, name: false }
|
|
234
|
+
```
|
|
235
|
+
8. **exists**: To return items based on the existence of certain fields, the `exists` keyword is used. Prepend the minus (-) sign to achieve the opposite.
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
GET https://go-mailer.com?exists=age,-state
|
|
239
|
+
|
|
240
|
+
// evaluates to
|
|
241
|
+
{ age: { $exists: true }, state: { $exists: false } }
|
|
242
|
+
```
|
|
227
243
|
|
|
228
244
|
### **Special Characters**
|
|
229
245
|
The use of special characters in query values indicate the need to prepare the following queries:
|
package/lib/query.js
CHANGED
|
@@ -2,14 +2,29 @@ const buildQuery = (options) => {
|
|
|
2
2
|
const sort_condition = options.sort_by ? buildSortOrderString(options.sort_by) : ''
|
|
3
3
|
const fields_to_return = options.return_only ? buildReturnFieldsString(options.return_only) : ''
|
|
4
4
|
const count = options.count || false
|
|
5
|
-
const seek_conditions = options.bool ? { ...buildBooleanQuery(options.bool || '') } : {}
|
|
6
5
|
const group_by = options.group_by || null
|
|
6
|
+
|
|
7
|
+
let seek_conditions = {}
|
|
8
|
+
if (options.bool){
|
|
9
|
+
seek_conditions = {
|
|
10
|
+
...seek_conditions,
|
|
11
|
+
...buildBooleanQuery(options.bool || '')
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (options.exists) {
|
|
16
|
+
seek_conditions = {
|
|
17
|
+
...seek_conditions,
|
|
18
|
+
...buildExistsQuery(options.exists || '')
|
|
19
|
+
}
|
|
20
|
+
}
|
|
7
21
|
|
|
8
22
|
const { skip, limit } = determinePagination(options.page, options.population)
|
|
9
23
|
|
|
10
24
|
/** Delete sort and return fields */
|
|
11
25
|
delete options.bool
|
|
12
26
|
delete options.count
|
|
27
|
+
delete options.exists
|
|
13
28
|
delete options.group_by
|
|
14
29
|
delete options.page
|
|
15
30
|
delete options.population
|
|
@@ -72,6 +87,23 @@ const buildBooleanQuery = (value) => {
|
|
|
72
87
|
}, {})
|
|
73
88
|
}
|
|
74
89
|
|
|
90
|
+
const buildExistsQuery = (value) => {
|
|
91
|
+
const values = value.split(',')
|
|
92
|
+
return values.reduce((sac, val) => {
|
|
93
|
+
let truthiness = true
|
|
94
|
+
let key = val
|
|
95
|
+
if (val[0] === '-') {
|
|
96
|
+
truthiness = false
|
|
97
|
+
key = val.substr(1)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
...sac,
|
|
102
|
+
[key]: { $exists: truthiness }
|
|
103
|
+
}
|
|
104
|
+
}, {})
|
|
105
|
+
}
|
|
106
|
+
|
|
75
107
|
const buildInQuery = (value) => {
|
|
76
108
|
const values = value.split(':')
|
|
77
109
|
return {
|