refactor code
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-11-09 10:19:27 +01:00
parent 79e9edcee9
commit 574f2757f4
1 changed files with 8 additions and 8 deletions

View File

@ -63,6 +63,7 @@ module.exports = Self => {
} }
let invoiceId; let invoiceId;
let invoiceOut;
try { try {
const client = await models.Client.findById(args.clientId, { const client = await models.Client.findById(args.clientId, {
fields: ['id', 'hasToInvoiceByAddress'] fields: ['id', 'hasToInvoiceByAddress']
@ -119,25 +120,24 @@ module.exports = Self => {
await notifyFailures(ctx, failedClient, myOptions); await notifyFailures(ctx, failedClient, myOptions);
} }
invoiceOut = await models.InvoiceOut.findById(invoiceId, {
include: {
relation: 'client'
}
}, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;
} }
const invoiceOut = await models.InvoiceOut.findById(invoiceId, {
include: {
relation: 'client'
}
});
ctx.args = { ctx.args = {
reference: invoiceOut.ref, reference: invoiceOut.ref,
recipientId: invoiceOut.clientFk, recipientId: invoiceOut.clientFk,
recipient: invoiceOut.client().email recipient: invoiceOut.client().email
}; };
try { await models.InvoiceOut.invoiceEmail(ctx);
await models.InvoiceOut.invoiceEmail(ctx);
} catch (err) {}
return invoiceId; return invoiceId;
}; };