From 5bd149f66ffc291083b97ccc42fd88391fd7327e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 24 Jul 2023 15:37:28 +0200 Subject: [PATCH] Use sdk to populate views --- packages/server/src/api/controllers/row/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 5ffc91c102..79a1d54c63 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -154,6 +154,16 @@ export async function searchView(ctx: Ctx) { ctx.throw(404, `View ${viewId} not found`) } + if (view.version !== 2) { + ctx.throw(400, `This method only supports viewsV2`) + } + + const table = await sdk.tables.getTable(view?.tableId) + + const viewFields = + view.columns?.length && + Object.keys(sdk.views.enrichSchema(view, table.schema).schema) + ctx.status = 200 ctx.body = await quotas.addQuery( () => @@ -163,7 +173,7 @@ export async function searchView(ctx: Ctx) { sort: view.sort?.field, sortOrder: view.sort?.order, sortType: view.sort?.type, - fields: view.columns, + fields: viewFields, }), { datasourceId: view.tableId,