From ce8730f176dfaa90d0d403ad75eb4e9d63b4af51 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 14 Aug 2024 12:30:01 +0200 Subject: [PATCH] Clean code --- packages/server/src/sdk/app/rows/search.ts | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index f4082a16fd..c96c0738d2 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -76,23 +76,17 @@ export async function search( const table = await sdk.tables.getTable(options.tableId) options = searchInputMapping(table, options) - const visibleTableFields = Object.keys(table.schema).filter( - f => table.schema[f].visible !== false - ) - - if (options.fields) { - const tableFields = visibleTableFields.map(f => f.toLowerCase()) - options.fields = options.fields.filter(f => - tableFields.includes(f.toLowerCase()) + if (options.query) { + const tableFields = Object.keys(table.schema).filter( + f => table.schema[f].visible !== false ) - } else { - options.fields = visibleTableFields - } - options.query = removeInvalidFilters( - options.query, - await getQueriableFields(options.fields, table) - ) + const queriableFields = await getQueriableFields( + options.fields?.filter(f => tableFields.includes(f)) ?? tableFields, + table + ) + options.query = removeInvalidFilters(options.query, queriableFields) + } let result: SearchResponse if (isExternalTable) {