Merge pull request '#7919 delete if ticketRefund' (!3091) from 7919-deleteTicketRefund into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3091 Reviewed-by: Carlos Andrés <carlosap@verdnatura.es> Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
b76b1c6d50
|
@ -49,9 +49,12 @@ module.exports = Self => {
|
|||
where: {originalTicketFk: id}
|
||||
}, myOptions);
|
||||
|
||||
const hasRefund = !!ticketRefunds?.length;
|
||||
|
||||
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 = [];
|
||||
for (const refund of ticketRefunds)
|
||||
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');
|
||||
});
|
||||
|
||||
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