Fix enrichments
This commit is contained in:
parent
0e468b04de
commit
c2e643cebb
|
@ -91,8 +91,11 @@ export async function find(ctx: UserCtx<void, TableResponse>) {
|
|||
const tableId = ctx.params.tableId
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
|
||||
let result = await sdk.tables.enrichRelationshipSchemas(table)
|
||||
result = sdk.tables.enrichViewSchemas(result)
|
||||
const enrichedSchema = await sdk.tables.enrichRelationshipSchema(table)
|
||||
const result = sdk.tables.enrichViewSchemas({
|
||||
...table,
|
||||
schema: enrichedSchema,
|
||||
})
|
||||
ctx.body = result
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
RelationshipFieldMetadata,
|
||||
Table,
|
||||
TableResponse,
|
||||
TableSchema,
|
||||
TableSourceType,
|
||||
TableViewsResponse,
|
||||
} from "@budibase/types"
|
||||
|
@ -144,9 +145,9 @@ export async function getTables(tableIds: string[]): Promise<Table[]> {
|
|||
return processTables(tables)
|
||||
}
|
||||
|
||||
export async function enrichRelationshipSchemas(
|
||||
export async function enrichRelationshipSchema(
|
||||
table: Table
|
||||
): Promise<TableResponse> {
|
||||
): Promise<TableSchema> {
|
||||
const tableCache: Record<string, Table> = {}
|
||||
|
||||
async function populateRelTableSchema(field: RelationshipFieldMetadata) {
|
||||
|
@ -179,14 +180,14 @@ export async function enrichRelationshipSchemas(
|
|||
}
|
||||
}
|
||||
|
||||
const result: TableResponse = { ...table, schema: {}, views: {} }
|
||||
const result: TableSchema = {}
|
||||
for (const fieldName of Object.keys(table.schema)) {
|
||||
const field = { ...table.schema[fieldName] }
|
||||
if (field.type === FieldType.LINK) {
|
||||
await populateRelTableSchema(field)
|
||||
}
|
||||
|
||||
result.schema[fieldName] = field
|
||||
result[fieldName] = field
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue