@go-mailer/jarvis 10.10.2 → 10.10.4

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.
Files changed (2) hide show
  1. package/lib/query.js +21 -7
  2. package/package.json +1 -1
package/lib/query.js CHANGED
@@ -110,30 +110,44 @@ const buildExistsQuery = (value) => {
110
110
  const buildInQuery = (value) => {
111
111
  const values = value.split(':')
112
112
  return {
113
- $in: [...values].map(val => isNaN(val) ? val : Number(val))
113
+ $in: [...values].map((val) => (isNaN(val) ? val : Number(val)))
114
114
  }
115
115
  }
116
116
 
117
117
  const buildNorQuery = (value) => {
118
118
  const values = value.split('!')
119
119
  return {
120
- $nin: [...values.slice(1)].map(val => isNaN(val) ? val : Number(val))
120
+ $nin: [...values].map((val) => (isNaN(val) ? val : Number(val)))
121
121
  }
122
122
  }
123
123
 
124
124
  const buildOrQuery = (value) => {
125
125
  const values = value.split(',')
126
126
  return {
127
- $in: [...values].map(val => isNaN(val) ? val : Number(val))
127
+ $in: [...values].map((val) => (isNaN(val) ? val : Number(val)))
128
128
  }
129
129
  }
130
130
 
131
131
  const buildRangeQuery = (value) => {
132
132
  const [min, max] = value.split('~')
133
- return {
134
- $gte: min ? Number(min) : Number.MIN_SAFE_INTEGER,
135
- $lte: max ? Number(max) : Number.MAX_SAFE_INTEGER
133
+ const is_not_number = !isNaN(min) || !isNaN(max)
134
+ const query = {
135
+ $gte: 0,
136
+ $lte: Number.MAX_SAFE_INTEGER
136
137
  }
138
+
139
+ if (is_not_number) {
140
+ const is_date = !isNaN(Date.parse(min)) || !isNaN(Date.parse(max))
141
+ if (is_date) {
142
+ query.$gte = min ? new Date(min) : new Date(0)
143
+ query.$lte = max ? new Date(max) : new Date()
144
+ }
145
+ } else {
146
+ query.$gte = min ? Number(min) : Number.MIN_SAFE_INTEGER
147
+ query.$lte = max ? Number(max) : Number.MAX_SAFE_INTEGER
148
+ }
149
+
150
+ return query
137
151
  }
138
152
 
139
153
  const buildReturnFieldsString = (value) => {
@@ -177,7 +191,7 @@ const generatePipeline = ({ group_by, seek_conditions, sort_condition, sum, fiel
177
191
  })
178
192
 
179
193
  let sort_options = sort_condition
180
- if (sort_condition && typeof (sort_condition) === 'string') {
194
+ if (sort_condition && typeof sort_condition === 'string') {
181
195
  sort_options = sort_condition.split(' ').reduce((sac, condition) => {
182
196
  let key = condition
183
197
  let value = 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-mailer/jarvis",
3
- "version": "10.10.2",
3
+ "version": "10.10.4",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:go-mailer-ltd/jarvis-node.git",
6
6
  "author": "Nathan Oguntuberu <nateoguns.work@gmail.com>",