Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function cleanQuery (query: any, operators: any, filters: any): any {
if (Array.isArray(query)) {
return query.map(value => cleanQuery(value, operators, filters));
} else if (_.isObject(query) && query.constructor === {}.constructor) {
const result: { [key: string]: any } = {};
_.each(query, (value, key) => {
if (key[0] === '$') {
if (filters[key] !== undefined) {
return;
}
if (!operators.includes(key)) {
throw new BadRequest(`Invalid query parameter ${key}`, query);
}
}
result[key] = cleanQuery(value, operators, filters);
});