From 855541f4e2f270ccf4d70e5cf1ba48ce248862ec Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 17 May 2026 14:00:42 +0530 Subject: [PATCH] fix(growth): convert dates to strings before SQL query Postgres driver expects strings, not Date objects Co-Authored-By: Claude Sonnet 4.6 --- src/app/api/growth/route.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/api/growth/route.ts b/src/app/api/growth/route.ts index 49f3570..e18271a 100644 --- a/src/app/api/growth/route.ts +++ b/src/app/api/growth/route.ts @@ -32,10 +32,11 @@ export async function POST(request: Request) { return NextResponse.json({ error: ownership.error }, { status: ownership.status }); } + const measuredAtDate = new Date(measuredAt).toISOString(); await sql.unsafe( `INSERT INTO growth (child_id, measured_at, weight_kg, height_cm, head_circumference_cm, notes) VALUES ($1, $2, $3, $4, $5, $6)`, - [childId, new Date(measuredAt), weightKg || null, heightCm || null, headCircumferenceCm || null, notes || null] + [childId, measuredAtDate, weightKg || null, heightCm || null, headCircumferenceCm || null, notes || null] ); return NextResponse.json({ success: true }); @@ -118,9 +119,10 @@ export async function PUT(request: Request) { return NextResponse.json({ error: "Not found" }, { status: 404 }); } + const measuredAtStr = measuredAt ? new Date(measuredAt).toISOString() : null; await sql.unsafe( `UPDATE growth SET measured_at = $1, weight_kg = $2, height_cm = $3, head_circumference_cm = $4, notes = $5 WHERE id = $6`, - [measuredAt ? new Date(measuredAt) : null, weightKg ?? null, heightCm ?? null, headCircumferenceCm ?? null, notes ?? null, id] + [measuredAtStr, weightKg ?? null, heightCm ?? null, headCircumferenceCm ?? null, notes ?? null, id] ); return NextResponse.json({ success: true });