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

23 lines
825 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;
let isEditable = await Self.app.models.Ticket.isEditable(ticketId);
if (!isEditable)
throw new UserError(`The current ticket can't be modified`);
2019-04-23 09:25:49 +00:00
}
});
Self.observe('before delete', async ctx => {
const models = Self.app.models;
const service = await models.TicketService.findById(ctx.where.id);
const isEditable = await Self.app.models.Ticket.isEditable(service.ticketFk);
if (!isEditable)
throw new UserError(`The current ticket can't be modified`);
});
2019-04-23 09:25:49 +00:00
};