diff --git a/src/app/api/annotations/route.ts b/src/app/api/annotations/route.ts index 41d8ef1..7848706 100644 --- a/src/app/api/annotations/route.ts +++ b/src/app/api/annotations/route.ts @@ -60,18 +60,27 @@ export async function POST(request: NextRequest) { ); } + // timestamp from client is Unix epoch seconds; convert to Date for Postgres + const timestampDate = typeof timestamp === 'number' + ? new Date(timestamp * 1000) + : new Date(timestamp); + const result = await db .insert(annotations) .values({ chart_id, - timestamp, + timestamp: timestampDate, label_type, geometry: geometry || null, color: color || '#3b82f6', }) .returning(); - return NextResponse.json(result[0], { status: 201 }); + const row = result[0]; + return NextResponse.json({ + ...row, + timestamp: row.timestamp instanceof Date ? Math.floor(row.timestamp.getTime() / 1000) : row.timestamp, + }, { status: 201 }); } catch (error: any) { return NextResponse.json( { error: error.message || 'Failed to create annotation' },