Making sure patch/save rows API alternate between each other as required.
This commit is contained in:
parent
09895b901a
commit
8c21cd5a19
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue