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

14 lines
481 B
JavaScript
Raw Normal View History

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 => {
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)
throw new UserError('You cannot add or modify services to an invoiced ticket');
2019-04-23 09:25:49 +00:00
}
});
};