ViewV2, return 404 if not found

This commit is contained in:
Adria Navarro 2025-01-16 16:55:24 +01:00
parent 029b7754ca
commit 325fea0c10
3 changed files with 11 additions and 5 deletions

View File

@ -123,9 +123,11 @@ async function parseSchema(view: CreateViewRequest) {
}
export async function get(ctx: Ctx<void, ViewResponseEnriched>) {
ctx.body = {
data: await sdk.views.getEnriched(ctx.params.viewId),
const view = await sdk.views.getEnriched(ctx.params.viewId)
if (!view) {
ctx.throw(404)
}
ctx.body = { data: view }
}
export async function fetch(ctx: Ctx<void, ViewFetchResponseEnriched>) {

View File

@ -40,7 +40,9 @@ export async function get(viewId: string): Promise<ViewV2> {
return pickApi(tableId).get(viewId)
}
export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
export async function getEnriched(
viewId: string
): Promise<ViewV2Enriched | undefined> {
const { tableId } = utils.extractViewInfoFromID(viewId)
return pickApi(tableId).getEnriched(viewId)
}

View File

@ -17,13 +17,15 @@ export async function get(viewId: string): Promise<ViewV2> {
return ensureQueryUISet(found)
}
export async function getEnriched(viewId: string): Promise<ViewV2Enriched> {
export async function getEnriched(
viewId: string
): Promise<ViewV2Enriched | undefined> {
const { tableId } = utils.extractViewInfoFromID(viewId)
const table = await sdk.tables.getTable(tableId)
const views = Object.values(table.views!).filter(isV2)
const found = views.find(v => v.id === viewId)
if (!found) {
throw new Error("No view found")
return
}
return await enrichSchema(ensureQueryUISet(found), table.schema)
}