Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const addFilter = function (esbResult, filter, filterName) {
let operator = filter.operator
switch (filter.type) {
case 'date':
if (moment(filter.values).isValid() || filter.values === 'now') {
esbResult = esbResult.filter(esb.rangeQuery(filterName)[operator](filter.values))
}
break
case 'term':
if (Array.isArray(filter.values)) {
const filterVals = filter.values.map((item) => {
// Check that filter fields aren't empty.
if (item.length > 0) {
return item
}
})
// Match any terms.
esbResult = esbResult.filter(esb.termsQuery(filterName, filterVals))
// Match all terms.
// esbResult = esbResult.should(esb.termsQuery(filterName, filterVals))
// esbResult = esbResult.minimumShouldMatch(filterField.length)
} else {