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