Skip to content

Commit 7d6eb90

Browse files
committed
Merge branch 'hotfix/2.1.8'
2 parents 179b441 + 65ca09f commit 7d6eb90

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

lib/mapper/filters.js

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function getCompareOperator(value) {
6666
else if (value.startsWith('gt')) return {'$gt': treatValue(value.slice(3))}
6767
else if (value.startsWith('lte')) return {'$lte': treatValue(value.slice(4))}
6868
else if (value.startsWith('lt')) return {'$lt': treatValue(value.slice(3))}
69+
else if (value.startsWith('ne')) return {'$ne': treatValue(value.slice(3))}
6970
return value
7071
}
7172

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "query-strings-parser",
3-
"version": "2.1.7",
3+
"version": "2.1.8",
44
"description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...",
55
"license": "MIT",
66
"main": "index.js",
@@ -20,7 +20,8 @@
2020
},
2121
"author": "Lucas Rocha <[email protected]>",
2222
"contributors": [
23-
"Douglas Rafael <[email protected]>"
23+
"Douglas Rafael <[email protected]>",
24+
"Jefferson Sampaio <[email protected]>"
2425
],
2526
"keywords": [
2627
"middleware",
@@ -42,10 +43,10 @@
4243
},
4344
"dependencies": {},
4445
"devDependencies": {
45-
"chai": "^4.2.0",
46+
"chai": "^4.3.4",
4647
"express": "^4.17.1",
47-
"mocha": "^8.1.3",
48+
"mocha": "^9.0.3",
4849
"nyc": "^15.1.0",
49-
"supertest": "^4.0.2"
50+
"supertest": "^6.1.4"
5051
}
5152
}

test/integration/index.default.config.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,29 @@ describe('queryFilter()', function () {
181181
validate(res.body, options)
182182
})
183183
})
184+
185+
it('should return req.query with set field params (with $ne filter)', function () {
186+
const expect_filters = {
187+
name: 'lucas',
188+
age: {$gt: 30},
189+
type: {$ne: 'admin'},
190+
timestamp: {$gt: '2018-12-05T00:00:00'},
191+
created_at: {$lte: '2018-12-06T00:00:00'},
192+
sleep_hour: '22:40'
193+
}
194+
195+
196+
const options = JSON.parse(JSON.stringify(default_options))
197+
options.default.filters = expect_filters
198+
199+
const query = '?name=lucas&age=gt:30&type=ne:admin&timestamp=gt:2018-12-05&created_at=lte:2018-12-06&sleep_hour=22:40'
200+
201+
return request(app)
202+
.get(query)
203+
.then(res => {
204+
validate(res.body, options)
205+
})
206+
})
184207
})
185208

186209
context('when query contains date filters param', function () {

0 commit comments

Comments
 (0)