Merge pull request '2315-client_web_access' (#301) from 2315-client_web_access into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2020-06-08 14:09:18 +00:00
commit 0a2366194a
1 changed files with 14 additions and 2 deletions

View File

@ -12,11 +12,23 @@ 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) {
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);
next(); if (!ctx.isNewInstance && ctx.data && (ctx.data.name || ctx.data.active)) {
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);
}
}); });
Self.remoteMethod('getCurrentUserData', { Self.remoteMethod('getCurrentUserData', {