Add error handling to accounts/ledger page

This commit is contained in:
Andymick
2026-07-18 08:54:04 +01:00
parent 3b5d1947dd
commit 2db94f6bd3
+24 -17
View File
@@ -33,23 +33,30 @@ export default async function AccountsPage({
// Include the whole "to" day, not just its midnight. // Include the whole "to" day, not just its midnight.
const to = searchParams.to ? new Date(`${searchParams.to}T23:59:59`) : null; const to = searchParams.to ? new Date(`${searchParams.to}T23:59:59`) : null;
const [orders, manualSales] = await Promise.all([ let orders = [];
type === 'manual' let manualSales = [];
? []
: prisma.order.findMany({ try {
where: { [orders, manualSales] = await Promise.all([
status: 'PAID', type === 'manual'
...(from || to ? { createdAt: { ...(from ? { gte: from } : {}), ...(to ? { lte: to } : {}) } } : {}), ? []
}, : prisma.order.findMany({
include: { items: true, customer: true }, where: {
}), status: 'PAID',
type === 'web' ...(from || to ? { createdAt: { ...(from ? { gte: from } : {}), ...(to ? { lte: to } : {}) } } : {}),
? [] },
: prisma.manualSale.findMany({ include: { items: true, customer: true },
where: from || to ? { soldAt: { ...(from ? { gte: from } : {}), ...(to ? { lte: to } : {}) } } : {}, }),
include: { items: true }, type === 'web'
}), ? []
]); : prisma.manualSale.findMany({
where: from || to ? { soldAt: { ...(from ? { gte: from } : {}), ...(to ? { lte: to } : {}) } } : {},
include: { items: true },
}),
]);
} catch (err) {
console.error('Error fetching ledger data:', err);
}
const entries: LedgerEntry[] = [ const entries: LedgerEntry[] = [
...orders.map((o) => ({ ...orders.map((o) => ({