Clean code

This commit is contained in:
Adria Navarro 2024-08-14 12:30:01 +02:00
parent 385c5f6e99
commit ce8730f176
1 changed files with 9 additions and 15 deletions

View File

@ -76,24 +76,18 @@ export async function search(
const table = await sdk.tables.getTable(options.tableId) const table = await sdk.tables.getTable(options.tableId)
options = searchInputMapping(table, options) options = searchInputMapping(table, options)
const visibleTableFields = Object.keys(table.schema).filter( if (options.query) {
const tableFields = Object.keys(table.schema).filter(
f => table.schema[f].visible !== false f => table.schema[f].visible !== false
) )
if (options.fields) { const queriableFields = await getQueriableFields(
const tableFields = visibleTableFields.map(f => f.toLowerCase()) options.fields?.filter(f => tableFields.includes(f)) ?? tableFields,
options.fields = options.fields.filter(f => table
tableFields.includes(f.toLowerCase())
) )
} else { options.query = removeInvalidFilters(options.query, queriableFields)
options.fields = visibleTableFields
} }
options.query = removeInvalidFilters(
options.query,
await getQueriableFields(options.fields, table)
)
let result: SearchResponse<Row> let result: SearchResponse<Row>
if (isExternalTable) { if (isExternalTable) {
span?.addTags({ searchType: "external" }) span?.addTags({ searchType: "external" })