Skip to content

Commit

Permalink
Merge branch 'hotfix/2.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsampaio committed Aug 5, 2021
2 parents 179b441 + 65ca09f commit 7d6eb90
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/mapper/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -20,7 +20,8 @@
},
"author": "Lucas Rocha <lucas.rocha@nutes.uepb.edu.br>",
"contributors": [
"Douglas Rafael <douglas.rafael@nutes.uepb.edu.br>"
"Douglas Rafael <douglas.rafael@nutes.uepb.edu.br>",
"Jefferson Sampaio <jefferson.medeiros@nutes.uepb.edu.br>"
],
"keywords": [
"middleware",
Expand All @@ -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"
}
}
23 changes: 23 additions & 0 deletions test/integration/index.default.config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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&timestamp=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 () {
Expand Down

0 comments on commit 7d6eb90

Please sign in to comment.