log web access, create hook in client
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
704e27a657
commit
d2aca11e16
|
@ -218,27 +218,34 @@ module.exports = Self => {
|
|||
await Self.app.models.ClientCredit.create(newCredit);
|
||||
}
|
||||
});
|
||||
// const app = require('vn-loopback/server/server');
|
||||
// Self.observe('loaded', async ctx => {
|
||||
// let account = Self.app.models.Account;
|
||||
// account.observe('after save', async ctx => {
|
||||
// console.log('ctx.isNewInstance', ctx.isNewInstance);
|
||||
// if (!ctx.isNewInstance && ctx.data && (ctx.data.name || ctx.data.active)) {
|
||||
// console.log('ctx.isNewInstance', ctx.isNewInstance);
|
||||
// let instance = JSON.parse(JSON.stringify(ctx.currentInstance));
|
||||
// let userId = ctx.options.accessToken.userId;
|
||||
// let logRecord = {
|
||||
// originFk: ctx.currentInstance.id,
|
||||
// userFk: userId,
|
||||
// action: 'update',
|
||||
// changedModel: 'Account',
|
||||
// oldInstance: {name: instance.name, active: instance.active},
|
||||
// newInstance: ctx.data
|
||||
// };
|
||||
// await Self.app.models.ClientLog.create(logRecord);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
const app = require('vn-loopback/server/server');
|
||||
|
||||
app.on('started', function() {
|
||||
let account = app.models.Account;
|
||||
account.observe('before save', async ctx => {
|
||||
if (ctx.isNewInstance) return;
|
||||
ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance));
|
||||
});
|
||||
account.observe('after save', async ctx => {
|
||||
let changes = ctx.data || ctx.instance;
|
||||
if (!ctx.isNewInstance && changes) {
|
||||
let oldData = ctx.hookState.oldInstance;
|
||||
let hasChanges = oldData.name != changes.name || oldData.active != changes.active;
|
||||
if (!hasChanges) return;
|
||||
|
||||
let userId = ctx.options.accessToken.userId;
|
||||
let logRecord = {
|
||||
originFk: oldData.id,
|
||||
userFk: userId,
|
||||
action: 'update',
|
||||
changedModel: 'Account',
|
||||
oldInstance: {name: oldData.name, active: oldData.active},
|
||||
newInstance: {name: changes.name, active: changes.active}
|
||||
};
|
||||
await Self.app.models.ClientLog.create(logRecord);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Self.observe('after save', async ctx => {
|
||||
if (ctx.isNewInstance) return;
|
||||
|
|
Loading…
Reference in New Issue