Fixing issue with modelId being returned from API causing next model update to cause model to be returned as a record from model record view.

This commit is contained in:
mike12345567 2020-09-29 18:03:29 +01:00
parent 672094b177
commit e798fca33b
2 changed files with 8 additions and 12 deletions

View File

@ -73,8 +73,6 @@ exports.save = async function(ctx) {
})
await db.put(designDoc)
// syntactic sugar for event emission
modelToSave.modelId = modelToSave._id
ctx.eventEmitter &&
ctx.eventEmitter.emitModel(`model:save`, instanceId, modelToSave)
ctx.status = 200
@ -109,8 +107,6 @@ exports.destroy = async function(ctx) {
delete designDoc.views[modelViewId]
await db.put(designDoc)
// syntactic sugar for event emission
modelToDelete.modelId = modelToDelete._id
ctx.eventEmitter &&
ctx.eventEmitter.emitModel(`model:delete`, instanceId, modelToDelete)
ctx.status = 200

View File

@ -20,9 +20,7 @@ class BudibaseEmitter extends EventEmitter {
if (model) {
event.model = model
}
if (record._id) {
event.id = record._id
}
event.id = record._id
if (record._rev) {
event.revision = record._rev
}
@ -30,14 +28,16 @@ class BudibaseEmitter extends EventEmitter {
}
emitModel(eventName, instanceId, model = null) {
const modelId = model._id
let event = {
model,
model: {
...model,
modelId: modelId,
},
instanceId,
modelId: model._id,
}
if (model._id) {
event.id = model._id
modelId: modelId,
}
event.id = modelId
if (model._rev) {
event.revision = model._rev
}