Merge pull request 'log refactor' (#469) from 2610-log_refactor into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #469
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2020-11-27 11:40:36 +00:00
commit 5dbf4f3926
1 changed files with 8 additions and 3 deletions

View File

@ -5,7 +5,6 @@
*/
exports.translateValues = async(instance, changes) => {
const models = instance.app.models;
function getRelation(instance, property) {
const relations = instance.definition.settings.relations;
for (let relationName in relations) {
@ -38,12 +37,18 @@ exports.translateValues = async(instance, changes) => {
for (let property in properties) {
const relation = getRelation(instance, property);
const value = properties[property];
let finalValue = value;
if (relation) {
let fieldsToShow = ['alias', 'name', 'code', 'description'];
const log = instance.definition.settings.log;
if (log && log.showField)
fieldsToShow = log.showField;
const model = relation.model;
const row = await models[model].findById(value, {
fields: ['alias', 'name', 'code', 'description']
fields: fieldsToShow
});
const newValue = getValue(row);
if (newValue) finalValue = newValue;