it should throw the error before it deletes the ticket

This commit is contained in:
Gerard 2018-11-20 11:48:12 +01:00
parent cb86e63e71
commit 9ce502551f
1 changed files with 3 additions and 3 deletions

View File

@ -22,13 +22,13 @@ module.exports = Self => {
});
Self.deleted = async (ctx, params) => {
let currentTicket = await Self.app.models.Ticket.findById(params.id);
await currentTicket.updateAttributes({isDeleted: '1'});
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
if (claimOfATicket)
throw new UserError('You must delete the claim id %d first', claimOfATicket.id);
let currentTicket = await Self.app.models.Ticket.findById(params.id);
await currentTicket.updateAttributes({isDeleted: '1'});
if (ctx.req.accessToken) {
let token = ctx.req.accessToken;
let currentUserId = token && token.userId;