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

55 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-10-08 14:00:19 +00:00
const LoopBackContext = require('loopback-context');
module.exports = Self => {
require('../methods/ticket/getVolume')(Self);
require('../methods/ticket/getTotalVolume')(Self);
2018-04-10 05:48:04 +00:00
require('../methods/ticket/summary')(Self);
require('../methods/ticket/priceDifference')(Self);
require('../methods/ticket/componentUpdate')(Self);
require('../methods/ticket/new')(Self);
require('../methods/ticket/isEditable')(Self);
require('../methods/ticket/setDeleted')(Self);
2020-10-08 11:42:20 +00:00
require('../methods/ticket/restore')(Self);
require('../methods/ticket/getSales')(Self);
require('../methods/ticket/getSalesPersonMana')(Self);
require('../methods/ticket/filter')(Self);
2019-04-05 10:24:39 +00:00
require('../methods/ticket/canBeInvoiced')(Self);
require('../methods/ticket/makeInvoice')(Self);
require('../methods/ticket/updateEditableTicket')(Self);
2019-08-09 06:04:44 +00:00
require('../methods/ticket/isEmpty')(Self);
2019-06-05 11:39:15 +00:00
require('../methods/ticket/updateDiscount')(Self);
require('../methods/ticket/uploadFile')(Self);
require('../methods/ticket/addSale')(Self);
2019-08-09 06:04:44 +00:00
require('../methods/ticket/transferSales')(Self);
2019-11-20 05:53:37 +00:00
require('../methods/ticket/recalculateComponents')(Self);
2020-01-15 12:27:14 +00:00
require('../methods/ticket/sendSms')(Self);
2020-02-27 11:31:38 +00:00
require('../methods/ticket/isLocked')(Self);
2020-09-09 13:49:59 +00:00
require('../methods/ticket/freightCost')(Self);
2020-07-21 09:11:09 +00:00
require('../methods/ticket/getComponentsSum')(Self);
require('../methods/ticket/refund')(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
};