Skip to content

Commit

Permalink
Fix filter compare value casting for filter operators that take 2 or …
Browse files Browse the repository at this point in the history
…more values (#22410)
  • Loading branch information
hanneskuettner committed May 8, 2024
1 parent 62e50fb commit 1a7bdb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-hats-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@directus/api': patch
---

Fixed `_between` and `_nbetween` filters using a function, such as `count()` and `year()`
10 changes: 5 additions & 5 deletions api/src/utils/apply-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ export function applyFilter(
const type = getOutputTypeForFunction(functionName);

if (['integer', 'float', 'decimal'].includes(type)) {
compareValue = Number(compareValue);
compareValue = Array.isArray(compareValue) ? compareValue.map(Number) : Number(compareValue);
}
}

Expand Down Expand Up @@ -789,20 +789,20 @@ export function applyFilter(
}

if (operator === '_between') {
if (compareValue.length !== 2) return;

let value = compareValue;
if (typeof value === 'string') value = value.split(',');

if (value.length !== 2) return;

dbQuery[logical].whereBetween(selectionRaw, value);
}

if (operator === '_nbetween') {
if (compareValue.length !== 2) return;

let value = compareValue;
if (typeof value === 'string') value = value.split(',');

if (value.length !== 2) return;

dbQuery[logical].whereNotBetween(selectionRaw, value);
}

Expand Down

0 comments on commit 1a7bdb1

Please sign in to comment.