From 874df3f54dfc658b9a501ba4a7df24e0201125b2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 14 Oct 2024 13:20:34 +0200 Subject: [PATCH] Fix wrong schema while fetching from datasource --- .../server/src/api/controllers/table/index.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/server/src/api/controllers/table/index.ts b/packages/server/src/api/controllers/table/index.ts index efe1a88e4a..2f2f93bffe 100644 --- a/packages/server/src/api/controllers/table/index.ts +++ b/packages/server/src/api/controllers/table/index.ts @@ -71,19 +71,20 @@ export async function fetch(ctx: UserCtx) { const datasources = await sdk.datasources.getExternalDatasources() - const external = datasources.flatMap(datasource => { + const external: Table[] = [] + for (const datasource of datasources) { let entities = datasource.entities if (entities) { - return Object.values(entities).map((entity: Table) => ({ - ...entity, - sourceType: TableSourceType.EXTERNAL, - sourceId: datasource._id!, - sql: isSQL(datasource), - })) - } else { - return [] + for (const entity of Object.values(entities)) { + external.push({ + ...(await processTable(entity)), + sourceType: TableSourceType.EXTERNAL, + sourceId: datasource._id!, + sql: isSQL(datasource), + }) + } } - }) + } const result: FetchTablesResponse = [] for (const table of [...internal, ...external]) {