From 574f2757f4414ac2b062e322f29debd30f42a145 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 9 Nov 2022 10:19:27 +0100 Subject: [PATCH] refactor code --- .../back/methods/invoiceOut/invoiceClient.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js index 7c8742caa..6667b5f0e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js +++ b/modules/invoiceOut/back/methods/invoiceOut/invoiceClient.js @@ -63,6 +63,7 @@ module.exports = Self => { } let invoiceId; + let invoiceOut; try { const client = await models.Client.findById(args.clientId, { fields: ['id', 'hasToInvoiceByAddress'] @@ -119,25 +120,24 @@ module.exports = Self => { await notifyFailures(ctx, failedClient, myOptions); } + invoiceOut = await models.InvoiceOut.findById(invoiceId, { + include: { + relation: 'client' + } + }, myOptions); + if (tx) await tx.commit(); } catch (e) { if (tx) await tx.rollback(); throw e; } - const invoiceOut = await models.InvoiceOut.findById(invoiceId, { - include: { - relation: 'client' - } - }); ctx.args = { reference: invoiceOut.ref, recipientId: invoiceOut.clientFk, recipient: invoiceOut.client().email }; - try { - await models.InvoiceOut.invoiceEmail(ctx); - } catch (err) {} + await models.InvoiceOut.invoiceEmail(ctx); return invoiceId; };