From c5f504d724d41c315e0ac52e1b41087d09564b3a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 7 Aug 2024 10:54:19 +0200 Subject: [PATCH] Use helper --- .../server/src/sdk/app/rows/search/internal/sqs.ts | 7 ++----- packages/shared-core/src/filters.ts | 13 +++++-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/packages/server/src/sdk/app/rows/search/internal/sqs.ts b/packages/server/src/sdk/app/rows/search/internal/sqs.ts index bbcbf2c7cd..66ec905c61 100644 --- a/packages/server/src/sdk/app/rows/search/internal/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/internal/sqs.ts @@ -2,7 +2,7 @@ import { Datasource, DocumentType, FieldType, - LogicalOperator, + isLogicalSearchOperator, Operation, QueryJson, RelationshipFieldMetadata, @@ -141,10 +141,7 @@ function cleanupFilters( const prefixFilters = (filters: SearchFilters) => { for (const filterKey of Object.keys(filters) as (keyof SearchFilters)[]) { - if ( - filterKey === LogicalOperator.AND || - filterKey === LogicalOperator.OR - ) { + if (isLogicalSearchOperator(filterKey)) { for (const condition of filters[filterKey]!.conditions) { prefixFilters(condition) } diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index e16e27fd30..e1a783175d 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -18,6 +18,7 @@ import { BasicOperator, RangeOperator, LogicalOperator, + isLogicalSearchOperator, } from "@budibase/types" import dayjs from "dayjs" import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants" @@ -359,10 +360,7 @@ export const buildQuery = (filter: SearchFilter[]) => { high: value, } } - } else if ( - queryOperator === LogicalOperator.AND || - queryOperator === LogicalOperator.OR - ) { + } else if (isLogicalSearchOperator(queryOperator)) { // TODO } else if (query[queryOperator] && operator !== "onEmptyFilter") { if (type === "boolean") { @@ -464,10 +462,9 @@ export const runQuery = (docs: Record[], query: SearchFilters) => { ) => (doc: Record) => { for (const [key, testValue] of Object.entries(query[type] || {})) { - const valueToCheck = - type === LogicalOperator.AND || type === LogicalOperator.OR - ? doc - : deepGet(doc, removeKeyNumbering(key)) + const valueToCheck = isLogicalSearchOperator(type) + ? doc + : deepGet(doc, removeKeyNumbering(key)) const result = test(valueToCheck, testValue) if (query.allOr && result) { return true