Fix undefined filter value (#8490)

* Fix undefined filter value

Fixes #8201

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Move isNil() before .map() & update error message

Fixes #8201

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

* Fix allowing to find null values

Signed-off-by: MattieBelt <mattiasvandenbelt@gmail.com>

Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
This commit is contained in:
Mattias van den Belt 2021-02-01 16:18:17 +01:00 committed by GitHub
parent 53c7fb0970
commit 23ead26f94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,8 +111,16 @@ const hasDeepFilters = ({ where = [], sort = [] }, { minDepth = 1 } = {}) => {
const normalizeWhereClauses = (whereClauses, { model }) => {
return whereClauses
.filter(({ value }) => !_.isNil(value))
.filter(({ value }) => !_.isNull(value))
.map(({ field, operator, value }) => {
if (_.isUndefined(value)) {
const err = new Error(
`The value of field: '${field}', in your where filter, is undefined.`
);
err.status = 400;
throw err;
}
if (BOOLEAN_OPERATORS.includes(operator)) {
return {
field,