fix: dashboard $queryRaw Date serialization with custom toJSON override
Prisma $queryRaw template literal interpolation fails when Date objects are passed directly and Date.prototype.toJSON is overridden (returns local time string instead of UTC ISO). MySQL driver receives a nested JSON object instead of a flat parameter array. Fix: convert monthStart/monthEnd to strings via toJSON() before interpolating into the $queryRaw template literal. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
`,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user