2019-07-03 06:29:40 +00:00
|
|
|
|
2020-10-08 14:00:19 +00:00
|
|
|
const LoopBackContext = require('loopback-context');
|
|
|
|
|
2018-05-04 09:46:03 +00:00
|
|
|
module.exports = Self => {
|
2022-09-29 07:07:18 +00:00
|
|
|
// Methods
|
|
|
|
require('./ticket-methods')(Self);
|
2019-07-03 06:29:40 +00:00
|
|
|
|
|
|
|
Self.observe('before save', async function(ctx) {
|
2020-10-08 14:00:19 +00:00
|
|
|
const loopBackContext = LoopBackContext.getCurrentContext();
|
|
|
|
const httpCtx = loopBackContext.active;
|
|
|
|
|
2019-07-03 06:29:40 +00:00
|
|
|
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;
|
2019-07-03 06:29:40 +00:00
|
|
|
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
|
|
|
};
|