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 tableId = ctx.params.tableId
|
||||||
const table = await sdk.tables.getTable(tableId)
|
const table = await sdk.tables.getTable(tableId)
|
||||||
|
|
||||||
let result = await sdk.tables.enrichRelationshipSchemas(table)
|
const enrichedSchema = await sdk.tables.enrichRelationshipSchema(table)
|
||||||
result = sdk.tables.enrichViewSchemas(result)
|
const result = sdk.tables.enrichViewSchemas({
|
||||||
|
...table,
|
||||||
|
schema: enrichedSchema,
|
||||||
|
})
|
||||||
ctx.body = result
|
ctx.body = result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
RelationshipFieldMetadata,
|
RelationshipFieldMetadata,
|
||||||
Table,
|
Table,
|
||||||
TableResponse,
|
TableResponse,
|
||||||
|
TableSchema,
|
||||||
TableSourceType,
|
TableSourceType,
|
||||||
TableViewsResponse,
|
TableViewsResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -144,9 +145,9 @@ export async function getTables(tableIds: string[]): Promise<Table[]> {
|
||||||
return processTables(tables)
|
return processTables(tables)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function enrichRelationshipSchemas(
|
export async function enrichRelationshipSchema(
|
||||||
table: Table
|
table: Table
|
||||||
): Promise<TableResponse> {
|
): Promise<TableSchema> {
|
||||||
const tableCache: Record<string, Table> = {}
|
const tableCache: Record<string, Table> = {}
|
||||||
|
|
||||||
async function populateRelTableSchema(field: RelationshipFieldMetadata) {
|
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)) {
|
for (const fieldName of Object.keys(table.schema)) {
|
||||||
const field = { ...table.schema[fieldName] }
|
const field = { ...table.schema[fieldName] }
|
||||||
if (field.type === FieldType.LINK) {
|
if (field.type === FieldType.LINK) {
|
||||||
await populateRelTableSchema(field)
|
await populateRelTableSchema(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.schema[fieldName] = field
|
result[fieldName] = field
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue