Fix external save/update

This commit is contained in:
Adria Navarro 2023-09-27 16:20:41 +02:00
parent ab97093a06
commit 1fb3c4b3c3
1 changed files with 16 additions and 15 deletions

View File

@ -49,14 +49,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
const tableId = utils.getTableId(ctx)
const { _id, ...rowData } = ctx.request.body
const validateResult = await sdk.rows.utils.validate({
row: rowData,
tableId,
})
if (!validateResult.valid) {
throw { validation: validateResult.errors }
}
const table = await sdk.tables.getTable(tableId)
const { row: dataToUpdate } = await inputProcessing(
ctx.user?._id,
@ -64,6 +56,14 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
rowData
)
const validateResult = await sdk.rows.utils.validate({
row: dataToUpdate,
tableId,
})
if (!validateResult.valid) {
throw { validation: validateResult.errors }
}
const response = await handleRequest(Operation.UPDATE, tableId, {
id: breakRowIdField(_id),
row: dataToUpdate,
@ -81,13 +81,6 @@ export async function patch(ctx: UserCtx<PatchRowRequest, PatchRowResponse>) {
export async function save(ctx: UserCtx) {
const inputs = ctx.request.body
const tableId = utils.getTableId(ctx)
const validateResult = await sdk.rows.utils.validate({
row: inputs,
tableId,
})
if (!validateResult.valid) {
throw { validation: validateResult.errors }
}
const table = await sdk.tables.getTable(tableId)
const { table: updatedTable, row } = await inputProcessing(
@ -96,6 +89,14 @@ export async function save(ctx: UserCtx) {
inputs
)
const validateResult = await sdk.rows.utils.validate({
row,
tableId,
})
if (!validateResult.valid) {
throw { validation: validateResult.errors }
}
const response = await handleRequest(Operation.CREATE, tableId, {
row,
})