refactor: refs #6760 ticketsIds improved
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-02-15 16:22:13 +01:00
parent fa7b94590d
commit 78583751ec
1 changed files with 12 additions and 8 deletions

View File

@ -22,7 +22,6 @@ module.exports = Self => {
Self.transferClient = async(ctx, id, clientFk, options) => {
const models = Self.app.models;
const myOptions = {};
const tickets = [];
let tx;
if (typeof options == 'object')
@ -36,7 +35,7 @@ module.exports = Self => {
try {
await Self.isEditableOrThrow(ctx, id, myOptions);
const ticketRelation = await models.TicketRefund.findOne({
const ticketRefund = await models.TicketRefund.findOne({
where: {or: [{originalTicketFk: id}, {refundTicketFk: id}]},
include: [{relation: 'refundTicket'}, {relation: 'originalTicket'}]
}, myOptions);
@ -46,16 +45,21 @@ module.exports = Self => {
const attributes = {clientFk, addressFk};
if (ticketRelation) {
const {refundTicket, originalTicket} = ticketRelation;
const tickets = [];
const ticketIds = [];
if (ticketRefund) {
const {refundTicket, originalTicket} = ticketRefund;
tickets.push(refundTicket(), originalTicket());
for (const ticket of tickets)
for (const ticket of tickets) {
await ticket.updateAttributes(attributes, myOptions);
} else
ticketIds.push(ticket.id);
}
} else {
await Self.updateAll({id}, attributes, myOptions);
const ticketIds = tickets.length ? tickets.map(ticket => ticket.id) : [id];
ticketIds.push(id);
}
await models.Claim.updateAll({ticketFk: {inq: ticketIds}}, {clientFk}, myOptions);