Use helper
This commit is contained in:
parent
24463bd387
commit
c5f504d724
|
@ -2,7 +2,7 @@ import {
|
||||||
Datasource,
|
Datasource,
|
||||||
DocumentType,
|
DocumentType,
|
||||||
FieldType,
|
FieldType,
|
||||||
LogicalOperator,
|
isLogicalSearchOperator,
|
||||||
Operation,
|
Operation,
|
||||||
QueryJson,
|
QueryJson,
|
||||||
RelationshipFieldMetadata,
|
RelationshipFieldMetadata,
|
||||||
|
@ -141,10 +141,7 @@ function cleanupFilters(
|
||||||
|
|
||||||
const prefixFilters = (filters: SearchFilters) => {
|
const prefixFilters = (filters: SearchFilters) => {
|
||||||
for (const filterKey of Object.keys(filters) as (keyof SearchFilters)[]) {
|
for (const filterKey of Object.keys(filters) as (keyof SearchFilters)[]) {
|
||||||
if (
|
if (isLogicalSearchOperator(filterKey)) {
|
||||||
filterKey === LogicalOperator.AND ||
|
|
||||||
filterKey === LogicalOperator.OR
|
|
||||||
) {
|
|
||||||
for (const condition of filters[filterKey]!.conditions) {
|
for (const condition of filters[filterKey]!.conditions) {
|
||||||
prefixFilters(condition)
|
prefixFilters(condition)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
BasicOperator,
|
BasicOperator,
|
||||||
RangeOperator,
|
RangeOperator,
|
||||||
LogicalOperator,
|
LogicalOperator,
|
||||||
|
isLogicalSearchOperator,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
|
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
|
||||||
|
@ -359,10 +360,7 @@ export const buildQuery = (filter: SearchFilter[]) => {
|
||||||
high: value,
|
high: value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (isLogicalSearchOperator(queryOperator)) {
|
||||||
queryOperator === LogicalOperator.AND ||
|
|
||||||
queryOperator === LogicalOperator.OR
|
|
||||||
) {
|
|
||||||
// TODO
|
// TODO
|
||||||
} else if (query[queryOperator] && operator !== "onEmptyFilter") {
|
} else if (query[queryOperator] && operator !== "onEmptyFilter") {
|
||||||
if (type === "boolean") {
|
if (type === "boolean") {
|
||||||
|
@ -464,10 +462,9 @@ export const runQuery = (docs: Record<string, any>[], query: SearchFilters) => {
|
||||||
) =>
|
) =>
|
||||||
(doc: Record<string, any>) => {
|
(doc: Record<string, any>) => {
|
||||||
for (const [key, testValue] of Object.entries(query[type] || {})) {
|
for (const [key, testValue] of Object.entries(query[type] || {})) {
|
||||||
const valueToCheck =
|
const valueToCheck = isLogicalSearchOperator(type)
|
||||||
type === LogicalOperator.AND || type === LogicalOperator.OR
|
? doc
|
||||||
? doc
|
: deepGet(doc, removeKeyNumbering(key))
|
||||||
: deepGet(doc, removeKeyNumbering(key))
|
|
||||||
const result = test(valueToCheck, testValue)
|
const result = test(valueToCheck, testValue)
|
||||||
if (query.allOr && result) {
|
if (query.allOr && result) {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue