mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-20 13:34:30 +01:00
chore: fix when no payments or invoices
This commit is contained in:
parent
b51dca146d
commit
c58302da2a
2 changed files with 25 additions and 18 deletions
|
@ -52,7 +52,7 @@
|
|||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick"
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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],
|
||||
|
|
Loading…
Add table
Reference in a new issue