Fix for multiple _ne operators (#1013)

When filtering with multiple _ne it should use logical AND instead of OR to verify that all checks succeed, close #929
This commit is contained in:
Filippo Conti
2019-09-02 18:30:35 +02:00
committed by typicode
parent 4f315b090f
commit ae1428375d
2 changed files with 19 additions and 5 deletions

View File

@ -116,13 +116,14 @@ module.exports = (db, name, opts) => {
// Always use an array, in case req.query is an array
const arr = [].concat(req.query[key])
const isDifferent = /_ne$/.test(key)
const isRange = /_lte$/.test(key) || /_gte$/.test(key)
const isLike = /_like$/.test(key)
const path = key.replace(/(_lte|_gte|_ne|_like)$/, '')
chain = chain.filter(element => {
return arr
.map(function(value) {
const isDifferent = /_ne$/.test(key)
const isRange = /_lte$/.test(key) || /_gte$/.test(key)
const isLike = /_like$/.test(key)
const path = key.replace(/(_lte|_gte|_ne|_like)$/, '')
// get item value based on path
// i.e post.title -> 'foo'
const elementValue = _.get(element, path)
@ -146,7 +147,7 @@ module.exports = (db, name, opts) => {
return value === elementValue.toString()
}
})
.reduce((a, b) => a || b)
.reduce((a, b) => (isDifferent ? a && b : a || b))
})
}
})