Use sdk to populate views

This commit is contained in:
Adria Navarro 2023-07-24 15:37:28 +02:00
parent 1cf4e6e85a
commit 5bd149f66f
1 changed files with 11 additions and 1 deletions

View File

@ -154,6 +154,16 @@ export async function searchView(ctx: Ctx<void, SearchResponse>) {
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<void, SearchResponse>) {
sort: view.sort?.field,
sortOrder: view.sort?.order,
sortType: view.sort?.type,
fields: view.columns,
fields: viewFields,
}),
{
datasourceId: view.tableId,