Allow disable log on model properties
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-09-12 09:49:02 +02:00
parent 9bf54f34dd
commit e16d43b2fc
2 changed files with 35 additions and 1 deletions

View File

@ -211,6 +211,9 @@ module.exports = function(Self) {
let action = setActionType(ctx);
removeUnloggableProperties(definition, oldInstance);
removeUnloggableProperties(definition, newInstance);
let logRecord = {
originFk: originId,
userFk: userFk,
@ -223,12 +226,38 @@ module.exports = function(Self) {
};
let logsToSave = setLogsToSave(where, changedModelId, logRecord, ctx);
let logModel = definition.settings.log.model;
await ctx.Model.app.models[logModel].create(logsToSave, options);
}
/**
* Removes unwanted properties
* @param {*} definition Model definition
* @param {*} properties Modified object properties
*/
function removeUnloggableProperties(definition, properties) {
const propList = Object.keys(properties);
const propDefs = new Map();
for (let property in definition.properties) {
const propertyDef = definition.properties[property];
propDefs.set(property, propertyDef);
}
for (let property of propList) {
const propertyDef = propDefs.get(property);
if (!propertyDef) return;
if (propertyDef.log === false)
delete properties[property];
else if (propertyDef.logValue === false)
properties[property] = null;
}
}
// this function retuns all the instances changed in case this is an updateAll
function setLogsToSave(changedInstances, changedInstancesIds, logRecord, ctx) {
let promises = [];

View File

@ -96,6 +96,11 @@
vn-tooltip="Add">
</vn-icon-button>
</div>
<div class="footer">
<div class="price" style="font-size: 8px">
<span>asdasdd</span>
</div>
</div>
</div>
</vn-card>
</section>