diff --git a/lib/mapper/filters.js b/lib/mapper/filters.js index e44bfa7..fd32141 100644 --- a/lib/mapper/filters.js +++ b/lib/mapper/filters.js @@ -66,6 +66,7 @@ function getCompareOperator(value) { else if (value.startsWith('gt')) return {'$gt': treatValue(value.slice(3))} else if (value.startsWith('lte')) return {'$lte': treatValue(value.slice(4))} else if (value.startsWith('lt')) return {'$lt': treatValue(value.slice(3))} + else if (value.startsWith('ne')) return {'$ne': treatValue(value.slice(3))} return value } diff --git a/package.json b/package.json index 1303e33..308473e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "query-strings-parser", - "version": "2.1.7", + "version": "2.1.8", "description": "Middleware to transform query strings in a format that is recognized by the MongoDB, MySQL and other databases...", "license": "MIT", "main": "index.js", @@ -20,7 +20,8 @@ }, "author": "Lucas Rocha ", "contributors": [ - "Douglas Rafael " + "Douglas Rafael ", + "Jefferson Sampaio " ], "keywords": [ "middleware", @@ -42,10 +43,10 @@ }, "dependencies": {}, "devDependencies": { - "chai": "^4.2.0", + "chai": "^4.3.4", "express": "^4.17.1", - "mocha": "^8.1.3", + "mocha": "^9.0.3", "nyc": "^15.1.0", - "supertest": "^4.0.2" + "supertest": "^6.1.4" } } diff --git a/test/integration/index.default.config.spec.js b/test/integration/index.default.config.spec.js index 86fabfc..8283b76 100644 --- a/test/integration/index.default.config.spec.js +++ b/test/integration/index.default.config.spec.js @@ -181,6 +181,29 @@ describe('queryFilter()', function () { validate(res.body, options) }) }) + + it('should return req.query with set field params (with $ne filter)', function () { + const expect_filters = { + name: 'lucas', + age: {$gt: 30}, + type: {$ne: 'admin'}, + timestamp: {$gt: '2018-12-05T00:00:00'}, + created_at: {$lte: '2018-12-06T00:00:00'}, + sleep_hour: '22:40' + } + + + const options = JSON.parse(JSON.stringify(default_options)) + options.default.filters = expect_filters + + const query = '?name=lucas&age=gt:30&type=ne:admin×tamp=gt:2018-12-05&created_at=lte:2018-12-06&sleep_hour=22:40' + + return request(app) + .get(query) + .then(res => { + validate(res.body, options) + }) + }) }) context('when query contains date filters param', function () {