refactor: delete unnecessary code

This commit is contained in:
Vicent Llopis 2022-10-17 11:42:05 +02:00
parent 6924b05c8a
commit 33092acee7
2 changed files with 12 additions and 27 deletions

View File

@ -26,18 +26,6 @@ module.exports = Self => {
description: 'The maximum shipped date', description: 'The maximum shipped date',
required: true required: true
}, },
{
arg: 'fromClientId',
type: 'number',
description: 'The minimum client id',
required: true
},
{
arg: 'toClientId',
type: 'number',
description: 'The maximum client id',
required: true
},
{ {
arg: 'companyFk', arg: 'companyFk',
type: 'number', type: 'number',
@ -47,7 +35,7 @@ module.exports = Self => {
{ {
arg: 'minShipped', arg: 'minShipped',
type: 'date', type: 'date',
description: 'The company id to invoice', description: 'The minium shupped date',
required: true required: true
}], }],
returns: { returns: {
@ -74,13 +62,14 @@ module.exports = Self => {
myOptions.transaction = tx; myOptions.transaction = tx;
} }
const invoicesIds = []; let invoiceId;
const failedClients = [];
try { try {
const client = await models.Client.findById(args.clientId, { const client = await models.Client.findById(args.clientId, {
fields: ['id', 'hasToInvoiceByAddress'] fields: ['id', 'hasToInvoiceByAddress']
}, myOptions); }, myOptions);
try { try {
throw new Error(`Pq lo digo yo`);
if (client.hasToInvoiceByAddress) { if (client.hasToInvoiceByAddress) {
await Self.rawSql('CALL ticketToInvoiceByAddress(?, ?, ?, ?)', [ await Self.rawSql('CALL ticketToInvoiceByAddress(?, ?, ?, ?)', [
args.minShipped, args.minShipped,
@ -125,14 +114,14 @@ module.exports = Self => {
query = `INSERT IGNORE INTO invoiceOutQueue(invoiceFk) VALUES(?)`; query = `INSERT IGNORE INTO invoiceOutQueue(invoiceFk) VALUES(?)`;
await Self.rawSql(query, [newInvoice.id], myOptions); await Self.rawSql(query, [newInvoice.id], myOptions);
invoicesIds.push(newInvoice.id); invoiceId = newInvoice.id;
} }
} catch (e) { } catch (e) {
failedClients.push({ const failedClient = {
id: client.id, id: client.id,
stacktrace: e stacktrace: e
}); };
await notifyFailures(ctx, failedClients, myOptions); await notifyFailures(ctx, failedClient, myOptions);
} }
if (tx) await tx.commit(); if (tx) await tx.commit();
@ -141,7 +130,7 @@ module.exports = Self => {
throw e; throw e;
} }
return invoicesIds; return invoiceId;
}; };
async function getNegativeBase(options) { async function getNegativeBase(options) {
@ -166,7 +155,7 @@ module.exports = Self => {
return supplierCompany && supplierCompany.total; return supplierCompany && supplierCompany.total;
} }
async function notifyFailures(ctx, failedClients, options) { async function notifyFailures(ctx, failedClient, options) {
const models = Self.app.models; const models = Self.app.models;
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const $t = ctx.req.__; // $translate const $t = ctx.req.__; // $translate
@ -175,10 +164,8 @@ module.exports = Self => {
const subject = $t('Global invoicing failed'); const subject = $t('Global invoicing failed');
let body = $t(`Wasn't able to invoice the following clients`) + ':<br/><br/>'; let body = $t(`Wasn't able to invoice the following clients`) + ':<br/><br/>';
for (client of failedClients) { body += `ID: <strong>${failedClient.id}</strong>
body += `ID: <strong>${client.id}</strong> <br/> <strong>${failedClient.stacktrace}</strong><br/><br/>`;
<br/> <strong>${client.stacktrace}</strong><br/><br/>`;
}
await Self.rawSql(` await Self.rawSql(`
INSERT INTO vn.mail (sender, replyTo, sent, subject, body) INSERT INTO vn.mail (sender, replyTo, sent, subject, body)

View File

@ -83,8 +83,6 @@ class Controller extends Dialog {
addressId: clientAndAddress.addressId, addressId: clientAndAddress.addressId,
invoiceDate: invoice.invoiceDate, invoiceDate: invoice.invoiceDate,
maxShipped: invoice.maxShipped, maxShipped: invoice.maxShipped,
fromClientId: invoice.fromClientId,
toClientId: invoice.toClientId,
companyFk: invoice.companyFk, companyFk: invoice.companyFk,
minShipped: invoice.minShipped, minShipped: invoice.minShipped,