mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-06-15 00:49:18 +00:00
fix: Undefined values crashing the request (#476)
This commit is contained in:
@ -68,6 +68,11 @@ export function validateItem(validator: any | Array<any>, value: any, strict: bo
|
||||
validator = parseInt(validator)
|
||||
}
|
||||
|
||||
// do a comparaison with null values
|
||||
if (isNull(value)) {
|
||||
return isNull(validator)
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
// invert signal so that an early exit mean that a match was found!
|
||||
return !objectLoop(value, (v) => {
|
||||
@ -210,3 +215,14 @@ export function handleValidation(data: Array<any>, query: Query) {
|
||||
return validateItem(valueToValidate, v[key], query.strict)
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate that the value is null or undefined
|
||||
* @param value the value the check
|
||||
* @returns if the value is undefined or null or not
|
||||
*/
|
||||
function isNull(value: any): value is (undefined | null) {
|
||||
return typeof value === 'undefined' || value === null
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user