2019-04-23 09:25:49 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.observe('before save', async ctx => {
|
2019-04-24 05:43:11 +00:00
|
|
|
let changes = ctx.currentInstance || ctx.instance;
|
|
|
|
if (changes) {
|
|
|
|
let ticketId = changes.ticketFk;
|
2019-04-23 09:25:49 +00:00
|
|
|
let ticket = await Self.app.models.Ticket.findById(ticketId);
|
|
|
|
if (ticket.refFk)
|
2019-04-24 05:43:11 +00:00
|
|
|
throw new UserError('You cannot add or modify services to an invoiced ticket');
|
2019-04-23 09:25:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|