@go-mailer/jarvis 3.2.0 → 3.2.1
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 +5 -0
- package/lib/query.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -219,6 +219,11 @@ Keywords in request queries are used to prepare the following queries. Given the
|
|
|
219
219
|
```
|
|
220
220
|
GET https://go-mailer.com?count=1
|
|
221
221
|
```
|
|
222
|
+
6. **group**: To group items that match the query by a certain field, the `group_by` keyword is used.
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
GET https://go-mailer.com?group_by=age
|
|
226
|
+
```
|
|
222
227
|
|
|
223
228
|
### **Special Characters**
|
|
224
229
|
The use of special characters in query values indicate the need to prepare the following queries:
|
package/lib/query.js
CHANGED
|
@@ -3,6 +3,7 @@ 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 seek_conditions = options.bool ? { ...buildBooleanQuery(options.bool || '')} : {}
|
|
6
|
+
const group_by = options.group_by ? cleanGroupBy(options.group_by) : null
|
|
6
7
|
|
|
7
8
|
const { skip, limit } = determinePagination(options.page, options.population)
|
|
8
9
|
|
|
@@ -33,6 +34,7 @@ const buildQuery = (options) => {
|
|
|
33
34
|
|
|
34
35
|
return {
|
|
35
36
|
count,
|
|
37
|
+
group_by,
|
|
36
38
|
fields_to_return,
|
|
37
39
|
limit,
|
|
38
40
|
seek_conditions,
|
|
@@ -108,6 +110,12 @@ const buildWildcardOptions = (key_list, value) => {
|
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
const cleanGroupBy = (value) => {
|
|
114
|
+
if (!value || typeof value !== string) return null
|
|
115
|
+
|
|
116
|
+
return value.split(',')[0]
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
const determinePagination = (page = 0, population = Number.MAX_SAFE_INTEGER) => {
|
|
112
120
|
return {
|
|
113
121
|
limit: Number(population),
|