Fix patch issues
This commit is contained in:
parent
2d771c96dd
commit
14b5a42647
|
@ -45,6 +45,9 @@ export async function handleRequest<T extends Operation>(
|
||||||
export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
|
||||||
const source = await utils.getSource(ctx)
|
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)) {
|
if (sdk.views.isView(source) && helpers.views.isCalculationView(source)) {
|
||||||
ctx.throw(400, "Cannot update rows through a calculation view")
|
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 }
|
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,
|
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
|
// The id might have been changed, so the refetching would fail. Recalculating the id just in case
|
||||||
const updatedId =
|
const updatedId =
|
||||||
generateIdForRow({ ...beforeRow, ...dataToUpdate }, table) || _id
|
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,
|
relationships: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } {
|
||||||
if (docIds.isViewId(sourceId)) {
|
if (docIds.isViewId(sourceId)) {
|
||||||
return {
|
return {
|
||||||
tableId: utils.extractViewInfoFromID(sourceId).tableId,
|
tableId: utils.extractViewInfoFromID(sourceId).tableId,
|
||||||
viewId: sourceId,
|
viewId: encodeURI(sourceId),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) }
|
return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) }
|
||||||
|
|
Loading…
Reference in New Issue