Fix enrichments

This commit is contained in:
Adria Navarro 2024-08-21 17:56:44 +02:00
parent 0e468b04de
commit c2e643cebb
2 changed files with 10 additions and 6 deletions

View File

@ -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
}

View File

@ -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
}