mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Merge pull request #879 from nickrum/filter-query-fix
Use _and operator when converting filters to query
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Filter } from '@/types/';
|
||||
import { set, clone } from 'lodash';
|
||||
import { clone } from 'lodash';
|
||||
|
||||
export default function filtersToQuery(filters: readonly Filter[]) {
|
||||
const filterQuery: Record<string, any> = {};
|
||||
const filterList: Record<string, any>[] = [];
|
||||
|
||||
for (const filter of filters) {
|
||||
let { field, operator, value } = clone(filter) as any;
|
||||
@@ -13,7 +13,15 @@ export default function filtersToQuery(filters: readonly Filter[]) {
|
||||
|
||||
if (!value) continue;
|
||||
|
||||
set(filterQuery, field, { [`_${operator}`]: value });
|
||||
filterList.push({ [field]: { [`_${operator}`]: value } });
|
||||
}
|
||||
|
||||
let filterQuery: Record<string, any> = {};
|
||||
|
||||
if (filterList.length === 1) {
|
||||
filterQuery = filterList[0];
|
||||
} else if (filterList.length > 1) {
|
||||
filterQuery = { _and: filterList };
|
||||
}
|
||||
|
||||
return { filter: filterQuery };
|
||||
|
||||
Reference in New Issue
Block a user