Fix patch

This commit is contained in:
Adria Navarro 2024-06-07 11:39:36 +02:00
parent 20d1b81099
commit 853810704c
1 changed files with 6 additions and 1 deletions

View File

@ -56,13 +56,18 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
throw { validation: validateResult.errors }
}
const beforeRow = await sdk.rows.external.getRow(tableId, _id, {
relationships: true,
})
const response = await handleRequest(Operation.UPDATE, tableId, {
id: breakRowIdField(_id),
row: dataToUpdate,
})
// The id might have been changed, so the refetching would fail. Recalculating the id just in case
const updatedId = generateIdForRow(ctx.request.body, table)
const updatedId =
generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id
const row = await sdk.rows.external.getRow(tableId, updatedId, {
relationships: true,
})