ViewV2, return 404 if not found
This commit is contained in:
parent
029b7754ca
commit
325fea0c10
|
@ -123,9 +123,11 @@ async function parseSchema(view: CreateViewRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get(ctx: Ctx<void, ViewResponseEnriched>) {
|
export async function get(ctx: Ctx<void, ViewResponseEnriched>) {
|
||||||
ctx.body = {
|
const view = await sdk.views.getEnriched(ctx.params.viewId)
|
||||||
data: await sdk.views.getEnriched(ctx.params.viewId),
|
if (!view) {
|
||||||
|
ctx.throw(404)
|
||||||
}
|
}
|
||||||
|
ctx.body = { data: view }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetch(ctx: Ctx<void, ViewFetchResponseEnriched>) {
|
export async function fetch(ctx: Ctx<void, ViewFetchResponseEnriched>) {
|
||||||
|
|
|
@ -40,7 +40,9 @@ export async function get(viewId: string): Promise<ViewV2> {
|
||||||
return pickApi(tableId).get(viewId)
|
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)
|
const { tableId } = utils.extractViewInfoFromID(viewId)
|
||||||
return pickApi(tableId).getEnriched(viewId)
|
return pickApi(tableId).getEnriched(viewId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,15 @@ export async function get(viewId: string): Promise<ViewV2> {
|
||||||
return ensureQueryUISet(found)
|
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 { tableId } = utils.extractViewInfoFromID(viewId)
|
||||||
const table = await sdk.tables.getTable(tableId)
|
const table = await sdk.tables.getTable(tableId)
|
||||||
const views = Object.values(table.views!).filter(isV2)
|
const views = Object.values(table.views!).filter(isV2)
|
||||||
const found = views.find(v => v.id === viewId)
|
const found = views.find(v => v.id === viewId)
|
||||||
if (!found) {
|
if (!found) {
|
||||||
throw new Error("No view found")
|
return
|
||||||
}
|
}
|
||||||
return await enrichSchema(ensureQueryUISet(found), table.schema)
|
return await enrichSchema(ensureQueryUISet(found), table.schema)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue