refs #5036 changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-02-16 08:54:45 +01:00
parent e78ccd963e
commit f42fbb80ec
1 changed files with 18 additions and 10 deletions

View File

@ -386,8 +386,9 @@ class VnMySQL extends MySQL {
}
}
await this.createLogRecord(oldInstances, newInstances, model, opts);
await this.grabUserLog(model, opts, 'logout');
const hasGrabUser = await this.grabUserLog(model, opts, 'logout');
if(!hasGrabUser)
await this.createLogRecord(oldInstances, newInstances, model, opts);
if (tx) await tx.commit();
return res;
@ -397,31 +398,34 @@ class VnMySQL extends MySQL {
}
}
async grabUserLog(model, opts, logAction) {
async grabUserLog(model, opts, action) {
const Model = this.getModelDefinition(model).model;
const settings = Model.definition.settings;
if (!(settings.log && settings.log.grabUser))
return;
return false;
if (logAction === 'login') {
if(action == 'login'){
const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
const user = await Model.app.models.Account.findById(userId, {fields: ['name']}, opts);
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
} else
}
else if(action == 'logout'){
await this.executeP(`CALL account.myUser_logout()`, null, opts);
}
return true;
}
buildSelectStmt(op, data, idName, model, where, limit) {
const Model = this.getModelDefinition(model).model;
const settings = Model.definition.settings;
const properties = Object.keys(Model.definition.properties);
const log = settings.log;
const fields = data ? Object.keys(data) : [];
if (op == 'delete')
properties.forEach(property => fields.push(property));
else {
const log = Model.definition.settings.log;
fields.push(idName);
if (log.relation) fields.push(Model.relations[log.relation].keyFrom);
if (log.showField) fields.push(log.showField);
@ -512,9 +516,13 @@ class VnMySQL extends MySQL {
// Delete unchanged properties
if (oldI) {
Object.keys(oldI).forEach(prop => {
if (newI[prop] === oldI[prop]) {
delete newI[prop];
const hasChanges = oldI[prop] instanceof Date ?
oldI[prop]?.getTime() != newI[prop]?.getTime() :
oldI[prop] != newI[prop];
if (!hasChanges) {
delete oldI[prop];
delete newI[prop];
}
});
}