Remove unnecessary coercion
This commit is contained in:
parent
dac3fa0675
commit
80ff963082
|
@ -11,13 +11,10 @@ import {
|
||||||
AutomationStepSchema,
|
AutomationStepSchema,
|
||||||
AutomationStepType,
|
AutomationStepType,
|
||||||
EmptyFilterOption,
|
EmptyFilterOption,
|
||||||
SearchFilters,
|
|
||||||
Table,
|
|
||||||
SortOrder,
|
SortOrder,
|
||||||
QueryRowsStepInputs,
|
QueryRowsStepInputs,
|
||||||
QueryRowsStepOutputs,
|
QueryRowsStepOutputs,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { db as dbCore } from "@budibase/backend-core"
|
|
||||||
|
|
||||||
const SortOrderPretty = {
|
const SortOrderPretty = {
|
||||||
[SortOrder.ASCENDING]: "Ascending",
|
[SortOrder.ASCENDING]: "Ascending",
|
||||||
|
@ -95,40 +92,6 @@ async function getTable(appId: string, tableId: string) {
|
||||||
return ctx.body
|
return ctx.body
|
||||||
}
|
}
|
||||||
|
|
||||||
function typeCoercion(filters: SearchFilters, table: Table) {
|
|
||||||
if (!filters || !table) {
|
|
||||||
return filters
|
|
||||||
}
|
|
||||||
for (let key of Object.keys(filters)) {
|
|
||||||
const searchParam = filters[key as keyof SearchFilters]
|
|
||||||
if (typeof searchParam === "object") {
|
|
||||||
for (let [property, value] of Object.entries(searchParam)) {
|
|
||||||
// We need to strip numerical prefixes here, so that we can look up
|
|
||||||
// the correct field name in the schema
|
|
||||||
const columnName = dbCore.removeKeyNumbering(property)
|
|
||||||
const column = table.schema[columnName]
|
|
||||||
|
|
||||||
// convert string inputs
|
|
||||||
if (!column || typeof value !== "string") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (column.type === FieldType.NUMBER) {
|
|
||||||
if (key === "oneOf") {
|
|
||||||
// @ts-ignore TODO
|
|
||||||
searchParam[property] = value
|
|
||||||
.split(",")
|
|
||||||
.map(item => parseFloat(item))
|
|
||||||
} else {
|
|
||||||
// @ts-ignore TODO
|
|
||||||
searchParam[property] = parseFloat(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filters
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasNullFilters(filters: any[]) {
|
function hasNullFilters(filters: any[]) {
|
||||||
return (
|
return (
|
||||||
filters.length === 0 ||
|
filters.length === 0 ||
|
||||||
|
@ -159,7 +122,7 @@ export async function run({
|
||||||
sortType =
|
sortType =
|
||||||
fieldType === FieldType.NUMBER ? FieldType.NUMBER : FieldType.STRING
|
fieldType === FieldType.NUMBER ? FieldType.NUMBER : FieldType.STRING
|
||||||
}
|
}
|
||||||
const ctx: any = buildCtx(appId, null, {
|
const ctx = buildCtx(appId, null, {
|
||||||
params: {
|
params: {
|
||||||
tableId,
|
tableId,
|
||||||
},
|
},
|
||||||
|
@ -167,7 +130,7 @@ export async function run({
|
||||||
sortType,
|
sortType,
|
||||||
limit,
|
limit,
|
||||||
sort: sortColumn,
|
sort: sortColumn,
|
||||||
query: typeCoercion(filters || {}, table),
|
query: filters || {},
|
||||||
// default to ascending, like data tab
|
// default to ascending, like data tab
|
||||||
sortOrder: sortOrder || SortOrder.ASCENDING,
|
sortOrder: sortOrder || SortOrder.ASCENDING,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue