fix: convert Unix epoch seconds to Date before inserting annotation timestamp

This commit is contained in:
Marko Djordjevic 2026-02-17 19:46:24 +01:00
parent 148fe22cd7
commit 3a114cccd0

View file

@ -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' },