From 1fb3c4b3c3d8462344296b9933bcffcc2d28838c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 27 Sep 2023 16:20:41 +0200 Subject: [PATCH] Fix external save/update --- .../src/api/controllers/row/external.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/server/src/api/controllers/row/external.ts b/packages/server/src/api/controllers/row/external.ts index ec9a3e8fb0..7bb9eed6cc 100644 --- a/packages/server/src/api/controllers/row/external.ts +++ b/packages/server/src/api/controllers/row/external.ts @@ -49,14 +49,6 @@ export async function patch(ctx: UserCtx) { 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) { 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) { 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, })