From a96131a8142b2b3159e6110ccdad02dfc119f1aa Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 17 Jun 2021 12:21:13 +0100 Subject: [PATCH] Making sure patch/save rows API alternate between each other as required. --- packages/server/src/api/controllers/row/external.js | 3 --- packages/server/src/api/controllers/row/index.js | 10 ++++++++++ packages/server/src/api/controllers/row/internal.js | 5 ----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/server/src/api/controllers/row/external.js b/packages/server/src/api/controllers/row/external.js index d8f2a96c98..7efcc11c75 100644 --- a/packages/server/src/api/controllers/row/external.js +++ b/packages/server/src/api/controllers/row/external.js @@ -136,9 +136,6 @@ exports.patch = async ctx => { exports.save = async ctx => { const appId = ctx.appId const inputs = ctx.request.body - if (inputs._id) { - return exports.patch(ctx) - } const tableId = ctx.params.tableId return handleRequest(appId, DataSourceOperation.CREATE, tableId, { row: inputs, diff --git a/packages/server/src/api/controllers/row/index.js b/packages/server/src/api/controllers/row/index.js index 84e5341538..1d4b868e0a 100644 --- a/packages/server/src/api/controllers/row/index.js +++ b/packages/server/src/api/controllers/row/index.js @@ -24,6 +24,11 @@ function getTableId(ctx) { exports.patch = async ctx => { const appId = ctx.appId const tableId = getTableId(ctx) + const body = ctx.request.body + // if it doesn't have an _id then its save + if (body && !body._id) { + return exports.save(ctx) + } try { const { row, table } = await pickApi(tableId).patch(ctx) ctx.eventEmitter && @@ -38,6 +43,11 @@ exports.patch = async ctx => { exports.save = async function (ctx) { const appId = ctx.appId const tableId = getTableId(ctx) + const body = ctx.request.body + // if it has an ID already then its a patch + if (body && body._id) { + return exports.patch(ctx) + } try { const { row, table } = await pickApi(tableId).save(ctx) ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) diff --git a/packages/server/src/api/controllers/row/internal.js b/packages/server/src/api/controllers/row/internal.js index 0fd7659d40..2a55bcb333 100644 --- a/packages/server/src/api/controllers/row/internal.js +++ b/packages/server/src/api/controllers/row/internal.js @@ -95,11 +95,6 @@ exports.save = async function (ctx) { let inputs = ctx.request.body inputs.tableId = ctx.params.tableId - // if the row obj had an _id then it will have been retrieved - if (inputs._id && inputs._rev) { - return exports.patch(ctx) - } - if (!inputs._rev && !inputs._id) { inputs._id = generateRowID(inputs.tableId) }