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,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<Row>
if (isExternalTable) {