salix/modules/ticket/back/models/ticket.js

31 lines
980 B
JavaScript
Raw Normal View History

2020-10-08 14:00:19 +00:00
const LoopBackContext = require('loopback-context');
module.exports = Self => {
2022-09-29 07:07:18 +00:00
// Methods
require('./ticket-methods')(Self);
Self.observe('before save', async function(ctx) {
2020-10-08 14:00:19 +00:00
const loopBackContext = LoopBackContext.getCurrentContext();
const httpCtx = loopBackContext.active;
if (ctx.isNewInstance) return;
let changes = ctx.data || ctx.instance;
if (changes.routeFk === null && ctx.currentInstance.routeFk != null) {
let instance = JSON.parse(JSON.stringify(ctx.currentInstance));
2020-10-08 14:00:19 +00:00
let userId = httpCtx.accessToken.userId;
let logRecord = {
originFk: ctx.currentInstance.routeFk,
userFk: userId,
action: 'delete',
changedModel: 'Route',
oldInstance: {ticket: instance.id},
newInstance: null
};
await Self.app.models.RouteLog.create(logRecord);
}
});
2017-07-06 07:55:28 +00:00
};