8144-devToTest_2444 #3137
|
@ -49,9 +49,12 @@ module.exports = Self => {
|
||||||
where: {originalTicketFk: id}
|
where: {originalTicketFk: id}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
const hasRefund = !!ticketRefunds?.length;
|
||||||
|
|
||||||
const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted);
|
const allDeleted = ticketRefunds.every(refund => refund.refundTicket().isDeleted);
|
||||||
|
|
||||||
if (ticketRefunds?.length && !allDeleted) {
|
if (!hasRefund) await models.TicketRefund.destroyAll({refundTicketFk: id}, myOptions);
|
||||||
|
if (hasRefund && !allDeleted) {
|
||||||
const notDeleted = [];
|
const notDeleted = [];
|
||||||
for (const refund of ticketRefunds)
|
for (const refund of ticketRefunds)
|
||||||
if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id);
|
if (!refund.refundTicket().isDeleted) notDeleted.push(refund.refundTicket().id);
|
||||||
|
|
|
@ -113,5 +113,27 @@ describe('ticket setDeleted()', () => {
|
||||||
|
|
||||||
expect(error.message).not.toContain('Tickets with associated refunds');
|
expect(error.message).not.toContain('Tickets with associated refunds');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should delete the refund - original ticket relation', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ticketId = 24;
|
||||||
|
const refundTicket = await models.TicketRefund.findOne({where: {refundTicketFk: ticketId}}, options);
|
||||||
|
|
||||||
|
expect(refundTicket).toBeTruthy();
|
||||||
|
|
||||||
|
await models.Ticket.setDeleted(ctx, ticketId, options);
|
||||||
|
const removedRefundTicket = await models.TicketRefund.findOne({
|
||||||
|
where: {refundTicketFk: ticketId}},
|
||||||
|
options);
|
||||||
|
|
||||||
|
expect(removedRefundTicket).toBeNull();
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue