diff --git a/modules/entry/back/models/entry.js b/modules/entry/back/models/entry.js
index 6148ae559..d251634c4 100644
--- a/modules/entry/back/models/entry.js
+++ b/modules/entry/back/models/entry.js
@@ -11,6 +11,8 @@ module.exports = Self => {
require('../methods/entry/addFromBuy')(Self);
Self.observe('before save', async function(ctx, options) {
+ const models = Self.app.models;
+
if (ctx.isNewInstance) return;
const changes = ctx.data || ctx.instance;
@@ -21,6 +23,21 @@ module.exports = Self => {
const observationChanged = hasChanges
&& orgData.observation != observation;
+ const loopbackContext = LoopBackContext.getCurrentContext();
+ const userId = loopbackContext.active.accessToken.userId;
+
+ if (orgData.isConfirmed && orgData.editorFk) {
+ const {name} = await models.VnUser.findById(orgData.editorFk, null);
+ const to = `@${name}`;
+
+ let message = `
Changes
`;
+ for (const [key, value] of Object.entries(changes)) message += `- ${key}: ${value}
`;
+ message += '
';
+
+ ctx.req = loopbackContext.active;
+ await models.Chat.send(ctx, to, message);
+ }
+
if (observationChanged) {
let tx;
const myOptions = {};
@@ -34,8 +51,6 @@ module.exports = Self => {
}
try {
- const loopbackContext = LoopBackContext.getCurrentContext();
- const userId = loopbackContext.active.accessToken.userId;
const id = changes.id || orgData.id;
const entry = await Self.app.models.Entry.findById(id, null, myOptions);
await entry.updateAttribute('observationEditorFk', userId, myOptions);
diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json
index ab451219e..f29960b6f 100644
--- a/modules/entry/back/models/entry.json
+++ b/modules/entry/back/models/entry.json
@@ -74,6 +74,9 @@
},
"observationEditorFk": {
"type": "number"
+ },
+ "editorFk": {
+ "type": "number"
}
},
"relations": {