Fix patch issues

This commit is contained in:
Adria Navarro 2024-12-16 13:57:38 +01:00
parent 2d771c96dd
commit 14b5a42647
2 changed files with 6 additions and 3 deletions

View File

@ -45,6 +45,9 @@ export async function handleRequest<T extends Operation>(
export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
const source = await utils.getSource(ctx)
const { viewId, tableId } = utils.getSourceId(ctx)
const sourceId = viewId || tableId
if (sdk.views.isView(source) && helpers.views.isCalculationView(source)) {
ctx.throw(400, "Cannot update rows through a calculation view")
}
@ -66,7 +69,7 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
throw { validation: validateResult.errors }
}
const beforeRow = await sdk.rows.external.getRow(table._id!, _id, {
const beforeRow = await sdk.rows.external.getRow(sourceId, _id, {
relationships: true,
})
@ -78,7 +81,7 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
// The id might have been changed, so the refetching would fail. Recalculating the id just in case
const updatedId =
generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id
const row = await sdk.rows.external.getRow(table._id!, updatedId, {
const row = await sdk.rows.external.getRow(sourceId, updatedId, {
relationships: true,
})

View File

@ -66,7 +66,7 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } {
if (docIds.isViewId(sourceId)) {
return {
tableId: utils.extractViewInfoFromID(sourceId).tableId,
viewId: sourceId,
viewId: encodeURI(sourceId),
}
}
return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) }