1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00
This commit is contained in:
Adria Navarro 2024-08-07 12:37:37 +02:00
parent 8191552352
commit 42b6b6e919

View file

@ -5,12 +5,10 @@ import {
SearchViewRowRequest,
RequiredKeys,
RowSearchParams,
SearchFilterKey,
LogicalOperator,
} from "@budibase/types"
import { dataFilters } from "@budibase/shared-core"
import sdk from "../../../sdk"
import { db, context } from "@budibase/backend-core"
import { context } from "@budibase/backend-core"
import { enrichSearchContext } from "./utils"
export async function searchView(
@ -36,33 +34,15 @@ export async function searchView(
// that could let users find rows they should not be allowed to access.
let query = dataFilters.buildQuery(view.query || [])
if (body.query) {
// Extract existing fields
const existingFields =
view.query
?.filter(filter => filter.field)
.map(filter => db.removeKeyNumbering(filter.field)) || []
// Delete extraneous search params that cannot be overridden
delete body.query.allOr
delete body.query.onEmptyFilter
// Carry over filters for unused fields
Object.keys(body.query).forEach(key => {
const operator = key as SearchFilterKey
Object.keys(body.query[operator] || {}).forEach(field => {
if (!existingFields.includes(db.removeKeyNumbering(field))) {
if (
operator === LogicalOperator.AND ||
operator === LogicalOperator.OR
) {
// TODO
} else {
query[operator]![field] = body.query[operator]![field]
}
}
})
})
query = {
$and: {
conditions: [query, body.query],
},
}
}
await context.ensureSnippetContext(true)