Fixing up column renaming everywhere that it is needed, making sure works for external as well.
This commit is contained in:
parent
aa1eaa1d3d
commit
48672244f4
|
@ -45,6 +45,7 @@ import { db as dbCore } from "@budibase/backend-core"
|
|||
import sdk from "../../../sdk"
|
||||
import env from "../../../environment"
|
||||
import { makeExternalQuery } from "../../../integrations/base/query"
|
||||
import { dataFilters } from "@budibase/shared-core"
|
||||
|
||||
export interface ManyRelationship {
|
||||
tableId?: string
|
||||
|
@ -195,29 +196,33 @@ export class ExternalRequest<T extends Operation> {
|
|||
if (filters) {
|
||||
// need to map over the filters and make sure the _id field isn't present
|
||||
let prefix = 1
|
||||
for (const [operatorType, operator] of Object.entries(filters)) {
|
||||
const isArrayOp = sdk.rows.utils.isArrayFilter(operatorType)
|
||||
for (const field of Object.keys(operator || {})) {
|
||||
if (dbCore.removeKeyNumbering(field) === "_id") {
|
||||
if (primary) {
|
||||
const parts = breakRowIdField(operator[field])
|
||||
if (primary.length > 1 && isArrayOp) {
|
||||
operator[InternalSearchFilterOperator.COMPLEX_ID_OPERATOR] = {
|
||||
id: primary,
|
||||
values: parts[0],
|
||||
const checkFilters = (innerFilters: SearchFilters): SearchFilters => {
|
||||
for (const [operatorType, operator] of Object.entries(innerFilters)) {
|
||||
const isArrayOp = sdk.rows.utils.isArrayFilter(operatorType)
|
||||
for (const field of Object.keys(operator || {})) {
|
||||
if (dbCore.removeKeyNumbering(field) === "_id") {
|
||||
if (primary) {
|
||||
const parts = breakRowIdField(operator[field])
|
||||
if (primary.length > 1 && isArrayOp) {
|
||||
operator[InternalSearchFilterOperator.COMPLEX_ID_OPERATOR] = {
|
||||
id: primary,
|
||||
values: parts[0],
|
||||
}
|
||||
} else {
|
||||
for (let field of primary) {
|
||||
operator[`${prefix}:${field}`] = parts.shift()
|
||||
}
|
||||
prefix++
|
||||
}
|
||||
} else {
|
||||
for (let field of primary) {
|
||||
operator[`${prefix}:${field}`] = parts.shift()
|
||||
}
|
||||
prefix++
|
||||
}
|
||||
// make sure this field doesn't exist on any filter
|
||||
delete operator[field]
|
||||
}
|
||||
// make sure this field doesn't exist on any filter
|
||||
delete operator[field]
|
||||
}
|
||||
}
|
||||
return dataFilters.recurseLogicalOperators(innerFilters, checkFilters)
|
||||
}
|
||||
checkFilters(filters)
|
||||
}
|
||||
// there is no id, just use the user provided filters
|
||||
if (!idCopy || !table) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
Table,
|
||||
} from "@budibase/types"
|
||||
import { isPlainObject } from "lodash"
|
||||
import { dataFilters } from "@budibase/shared-core"
|
||||
|
||||
export function getRelationshipColumns(table: Table): {
|
||||
name: string
|
||||
|
@ -58,5 +59,7 @@ export function updateFilterKeys(
|
|||
}
|
||||
}
|
||||
}
|
||||
return filters
|
||||
return dataFilters.recurseLogicalOperators(filters, (f: SearchFilters) => {
|
||||
return updateFilterKeys(f, updates)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -139,29 +139,34 @@ function cleanupFilters(
|
|||
allTables.some(table => table.schema[key])
|
||||
|
||||
const splitter = new dataFilters.ColumnSplitter(allTables)
|
||||
for (const filterKey of Object.keys(filters) as (keyof SearchFilters)[]) {
|
||||
if (!isLogicalSearchOperator(filterKey)) {
|
||||
const filter = filters[filterKey]!
|
||||
if (typeof filter !== "object") {
|
||||
continue
|
||||
}
|
||||
for (const key of Object.keys(filter)) {
|
||||
const { numberPrefix, relationshipPrefix, column } = splitter.run(key)
|
||||
if (keyInAnyTable(column)) {
|
||||
filter[
|
||||
`${numberPrefix || ""}${relationshipPrefix || ""}${mapToUserColumn(
|
||||
column
|
||||
)}`
|
||||
] = filter[key]
|
||||
delete filter[key]
|
||||
|
||||
const prefixFilters = (filters: SearchFilters) => {
|
||||
for (const filterKey of Object.keys(filters) as (keyof SearchFilters)[]) {
|
||||
if (isLogicalSearchOperator(filterKey)) {
|
||||
for (const condition of filters[filterKey]!.conditions) {
|
||||
prefixFilters(condition)
|
||||
}
|
||||
} else {
|
||||
const filter = filters[filterKey]!
|
||||
if (typeof filter !== "object") {
|
||||
continue
|
||||
}
|
||||
for (const key of Object.keys(filter)) {
|
||||
const { numberPrefix, relationshipPrefix, column } = splitter.run(key)
|
||||
if (keyInAnyTable(column)) {
|
||||
filter[
|
||||
`${numberPrefix || ""}${
|
||||
relationshipPrefix || ""
|
||||
}${mapToUserColumn(column)}`
|
||||
] = filter[key]
|
||||
delete filter[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dataFilters.recurseLogicalOperators(filters, (f: SearchFilters) => {
|
||||
return cleanupFilters(f, table, allTables)
|
||||
})
|
||||
prefixFilters(filters)
|
||||
return filters
|
||||
}
|
||||
|
||||
function buildTableMap(tables: Table[]) {
|
||||
|
|
Loading…
Reference in New Issue