diff --git a/package.json b/package.json index 26de8a97..92669d5a 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "husky": { "hooks": { - "pre-commit": "pretty-quick" + "pre-commit": "pretty-quick --staged" } } } diff --git a/src/schemas/query/invoices/resume.ts b/src/schemas/query/invoices/resume.ts index 616a8404..e8668308 100644 --- a/src/schemas/query/invoices/resume.ts +++ b/src/schemas/query/invoices/resume.ts @@ -61,6 +61,7 @@ export const getResume = { let lastInvoiceDate = ''; let firstInvoiceDate = ''; let token = ''; + let withInvoices = true; try { const invoiceList: InvoicesProps = await getInvoices({ @@ -76,28 +77,34 @@ export const getResume = { }; }); - const { date } = invoices[invoices.length - 1]; - firstInvoiceDate = invoices[0].date; - lastInvoiceDate = date; - token = invoiceList.next; + if (invoices.length <= 0) { + withInvoices = false; + } else { + const { date } = invoices[invoices.length - 1]; + firstInvoiceDate = invoices[0].date; + lastInvoiceDate = date; + token = invoiceList.next; + } } catch (error) { logger.error('Error getting invoices: %o', error); throw new Error(getErrorMsg(error)); } - const filteredPayments = payments.filter(payment => { - const last = - compareDesc( - new Date(lastInvoiceDate), - new Date(payment.date), - ) === 1; - const first = - compareDesc( - new Date(payment.date), - new Date(firstInvoiceDate), - ) === 1; - return last && first; - }); + const filteredPayments = withInvoices + ? payments.filter(payment => { + const last = + compareDesc( + new Date(lastInvoiceDate), + new Date(payment.date), + ) === 1; + const first = + compareDesc( + new Date(payment.date), + new Date(firstInvoiceDate), + ) === 1; + return last && first; + }) + : payments; const resumeArray = sortBy( [...invoices, ...filteredPayments],