1
0
Fork 0
mirror of synced 2024-09-30 17:18:14 +13:00

Fixing an issue that a test case raised.

This commit is contained in:
mike12345567 2020-10-05 09:59:03 +01:00
parent 4663434e25
commit 39d0e084b8

View file

@ -24,7 +24,6 @@ exports.find = async function(ctx) {
exports.save = async function(ctx) {
const instanceId = ctx.user.instanceId
const db = new CouchDB(instanceId)
const oldModelId = ctx.request.body._id
const modelToSave = {
type: "model",
_id: generateModelID(),
@ -32,9 +31,15 @@ exports.save = async function(ctx) {
...ctx.request.body,
}
// get the model in its previous state for differencing
let oldModel = null
let oldModel
let oldModelId = ctx.request.body._id
if (oldModelId) {
oldModel = await db.get(oldModelId)
// if it errors then the oldModelId is invalid - can't diff it
try {
oldModel = await db.get(oldModelId)
} catch (err) {
oldModel = null
}
}
// rename record fields when table column is renamed