This commit is contained in:
parent
fa7b94590d
commit
78583751ec
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue