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);
|
require('../methods/entry/addFromBuy')(Self);
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx, options) {
|
Self.observe('before save', async function(ctx, options) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
|
||||||
if (ctx.isNewInstance) return;
|
if (ctx.isNewInstance) return;
|
||||||
|
|
||||||
const changes = ctx.data || ctx.instance;
|
const changes = ctx.data || ctx.instance;
|
||||||
|
@ -21,6 +23,21 @@ module.exports = Self => {
|
||||||
const observationChanged = hasChanges
|
const observationChanged = hasChanges
|
||||||
&& orgData.observation != observation;
|
&& 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) {
|
if (observationChanged) {
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
@ -34,8 +51,6 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const loopbackContext = LoopBackContext.getCurrentContext();
|
|
||||||
const userId = loopbackContext.active.accessToken.userId;
|
|
||||||
const id = changes.id || orgData.id;
|
const id = changes.id || orgData.id;
|
||||||
const entry = await Self.app.models.Entry.findById(id, null, myOptions);
|
const entry = await Self.app.models.Entry.findById(id, null, myOptions);
|
||||||
await entry.updateAttribute('observationEditorFk', userId, myOptions);
|
await entry.updateAttribute('observationEditorFk', userId, myOptions);
|
||||||
|
|
|
@ -74,6 +74,9 @@
|
||||||
},
|
},
|
||||||
"observationEditorFk": {
|
"observationEditorFk": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"editorFk": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
Loading…
Reference in New Issue