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