log web access

This commit is contained in:
Bernat Exposito Domenech 2020-06-08 10:19:24 +02:00
parent 0619c1b541
commit 79b143478e
1 changed files with 17 additions and 1 deletions

View File

@ -12,10 +12,26 @@ module.exports = Self => {
message: `A client with that Web User name already exists`
});
Self.observe('before save', (ctx, next) => {
Self.observe('before save', async function(ctx, next) {
if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password)
ctx.data.password = md5(ctx.data.password);
if (ctx.data && (ctx.data.name || ctx.data.active)) {
let instance = JSON.parse(JSON.stringify(ctx.currentInstance));
let userId = ctx.options.accessToken.userId;
console.log('ctx.data', ctx.data);
console.log('ctx.currentInstance', ctx.currentInstance);
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);
}
next();
});