diff --git a/src/routes/admin/dashboard.ts b/src/routes/admin/dashboard.ts index 8a9c525..f88dc88 100644 --- a/src/routes/admin/dashboard.ts +++ b/src/routes/admin/dashboard.ts @@ -179,6 +179,11 @@ export default async function dashboardRoutes( // Invoices — only for invoices.view if (has("invoices.view")) { + // $queryRaw template literal interpolation with Date objects fails on + // MySQL when Date.toJSON is overridden — pass strings instead. + const monthStartStr = monthStart.toJSON(); + const monthEndStr = monthEnd.toJSON(); + const [unpaidCount, revenueAgg] = await Promise.all([ prisma.invoices.count({ where: { status: "issued" } }), prisma.$queryRaw< @@ -187,7 +192,7 @@ export default async function dashboardRoutes( SELECT i.currency, SUM(ii.quantity * ii.unit_price) as total FROM invoices i JOIN invoice_items ii ON i.id = ii.invoice_id - WHERE i.issue_date >= ${monthStart} AND i.issue_date < ${monthEnd} + WHERE i.issue_date >= ${monthStartStr} AND i.issue_date < ${monthEndStr} GROUP BY i.currency `, ]);