log web access, create hook in client
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Bernat Exposito Domenech 2020-06-10 12:09:27 +02:00
parent 704e27a657
commit d2aca11e16
1 changed files with 28 additions and 21 deletions

View File

@ -218,27 +218,34 @@ module.exports = Self => {
await Self.app.models.ClientCredit.create(newCredit); await Self.app.models.ClientCredit.create(newCredit);
} }
}); });
// const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
// Self.observe('loaded', async ctx => {
// let account = Self.app.models.Account; app.on('started', function() {
// account.observe('after save', async ctx => { let account = app.models.Account;
// console.log('ctx.isNewInstance', ctx.isNewInstance); account.observe('before save', async ctx => {
// if (!ctx.isNewInstance && ctx.data && (ctx.data.name || ctx.data.active)) { if (ctx.isNewInstance) return;
// console.log('ctx.isNewInstance', ctx.isNewInstance); ctx.hookState.oldInstance = JSON.parse(JSON.stringify(ctx.currentInstance));
// let instance = JSON.parse(JSON.stringify(ctx.currentInstance)); });
// let userId = ctx.options.accessToken.userId; account.observe('after save', async ctx => {
// let logRecord = { let changes = ctx.data || ctx.instance;
// originFk: ctx.currentInstance.id, if (!ctx.isNewInstance && changes) {
// userFk: userId, let oldData = ctx.hookState.oldInstance;
// action: 'update', let hasChanges = oldData.name != changes.name || oldData.active != changes.active;
// changedModel: 'Account', if (!hasChanges) return;
// oldInstance: {name: instance.name, active: instance.active},
// newInstance: ctx.data let userId = ctx.options.accessToken.userId;
// }; let logRecord = {
// await Self.app.models.ClientLog.create(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 => { Self.observe('after save', async ctx => {
if (ctx.isNewInstance) return; if (ctx.isNewInstance) return;