1
0
Fork 0
mirror of synced 2024-08-12 08:31:27 +12:00

Fix trimming extra view fields and ensure empty views allow nothing

This commit is contained in:
Andrew Kingston 2023-08-14 12:04:36 +01:00
parent d1b3d033dd
commit a7b37a4550

View file

@ -23,7 +23,7 @@ export default async (ctx: Ctx<Row>, next: Next) => {
// don't need to trim delete requests
if (ctx?.method?.toLowerCase() !== "delete") {
await trimViewFields(ctx.request.body, viewId, tableId)
await trimViewFields(ctx.request.body, viewId)
}
ctx.params.sourceId = tableId
@ -35,17 +35,10 @@ export default async (ctx: Ctx<Row>, next: Next) => {
export async function trimViewFields<T extends Row>(
body: Row,
viewId: string,
tableId: string
): Promise<void> {
const view = await sdk.views.get(viewId)
if (!view?.schema || !Object.keys(view.schema).length) {
return
}
const table = await sdk.tables.getTable(tableId)
const { schema } = sdk.views.enrichSchema(view!, table.schema)
const allowedKeys = [
...Object.keys(schema),
...Object.keys(view?.schema || {}),
...db.CONSTANT_EXTERNAL_ROW_COLS,
...db.CONSTANT_INTERNAL_ROW_COLS,
]