1
0
Fork 0
mirror of synced 2024-06-03 02:55:14 +12:00

Making sure patch/save rows API alternate between each other as required.

This commit is contained in:
mike12345567 2021-06-17 12:21:13 +01:00
parent 09895b901a
commit 8c21cd5a19
3 changed files with 10 additions and 8 deletions

View file

@ -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,

View file

@ -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)

View file

@ -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)
}