#6760 modify transferClient #2035

Merged
jorgep merged 5 commits from 6760-modifyTransferClient into dev 2024-02-16 12:00:10 +00:00
1 changed files with 12 additions and 8 deletions
Showing only changes of commit 78583751ec - Show all commits

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);
}
jgallego marked this conversation as resolved Outdated

subir esto en las condiciones

subir esto en las condiciones
} 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);