From e798fca33bf7ae0b5a655e7437fb6e05f96a81c7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 29 Sep 2020 18:03:29 +0100 Subject: [PATCH] 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. --- packages/server/src/api/controllers/model.js | 4 ---- packages/server/src/events/index.js | 16 ++++++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/server/src/api/controllers/model.js b/packages/server/src/api/controllers/model.js index f223e0a99b..f4934583c3 100644 --- a/packages/server/src/api/controllers/model.js +++ b/packages/server/src/api/controllers/model.js @@ -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 diff --git a/packages/server/src/events/index.js b/packages/server/src/events/index.js index 13abacd761..d02cac447d 100644 --- a/packages/server/src/events/index.js +++ b/packages/server/src/events/index.js @@ -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 }