feat: refs #7025 notify changes on save
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
2291a92a43
commit
d94f37f1f9
|
@ -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 = `<h1>Changes</h1><ul>`;
|
||||
for (const [key, value] of Object.entries(changes)) message += `<li>${key}: ${value}</li>`;
|
||||
message += '</ul>';
|
||||
|
||||
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);
|
||||
|
|
|
@ -74,6 +74,9 @@
|
|||
},
|
||||
"observationEditorFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"editorFk": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
Loading…
Reference in New Issue