log web access
This commit is contained in:
parent
0619c1b541
commit
79b143478e
|
@ -12,10 +12,26 @@ module.exports = Self => {
|
||||||
message: `A client with that Web User name already exists`
|
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)
|
if (ctx.currentInstance && ctx.currentInstance.id && ctx.data && ctx.data.password)
|
||||||
ctx.data.password = md5(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();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue