Fix
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-05-26 15:49:20 +02:00
parent 8384918d9e
commit 3cd4ab086d
1 changed files with 4 additions and 5 deletions

View File

@ -13,6 +13,7 @@ module.exports = function(Self) {
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
const appModels = ctx.Model.app.models; const appModels = ctx.Model.app.models;
const definition = ctx.Model.definition;
const options = {}; const options = {};
// Check for transactions // Check for transactions
@ -29,7 +30,7 @@ module.exports = function(Self) {
if (ctx.where && !ctx.currentInstance) { if (ctx.where && !ctx.currentInstance) {
const fields = Object.keys(ctx.data); const fields = Object.keys(ctx.data);
const modelName = modelDef.name; const modelName = definition.name;
ctx.oldInstances = await appModels[modelName].find({ ctx.oldInstances = await appModels[modelName].find({
where: ctx.where, where: ctx.where,
@ -86,7 +87,7 @@ module.exports = function(Self) {
async function logDeletedInstances(ctx, loopBackContext) { async function logDeletedInstances(ctx, loopBackContext) {
const appModels = ctx.Model.app.models; const appModels = ctx.Model.app.models;
const modelDef = ctx.Model.definition; const definition = ctx.Model.definition;
let options = {}; let options = {};
if (ctx.options && ctx.options.transaction) if (ctx.options && ctx.options.transaction)
options.transaction = ctx.options.transaction; options.transaction = ctx.options.transaction;
@ -96,14 +97,12 @@ module.exports = function(Self) {
if (loopBackContext) if (loopBackContext)
userFk = loopBackContext.active.accessToken.userId; userFk = loopBackContext.active.accessToken.userId;
let definition = modelDef;
let changedModelValue = definition.settings.log.changedModelValue; let changedModelValue = definition.settings.log.changedModelValue;
let logRecord = { let logRecord = {
originFk: instance.originFk, originFk: instance.originFk,
userFk: userFk, userFk: userFk,
action: 'delete', action: 'delete',
changedModel: modelDef.name, changedModel: definition.name,
changedModelId: instance.id, changedModelId: instance.id,
changedModelValue: instance[changedModelValue], changedModelValue: instance[changedModelValue],
oldInstance: instance, oldInstance: instance,