diff --git a/loopback/common/models/loggable.js b/loopback/common/models/loggable.js index 781509e92..e62015440 100644 --- a/loopback/common/models/loggable.js +++ b/loopback/common/models/loggable.js @@ -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 = []; diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 550ac5cd9..0ede05776 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -96,6 +96,11 @@ vn-tooltip="Add"> +