fix: convert Unix epoch seconds to Date before inserting annotation timestamp
This commit is contained in:
parent
148fe22cd7
commit
3a114cccd0
1 changed files with 11 additions and 2 deletions
|
|
@ -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
|
const result = await db
|
||||||
.insert(annotations)
|
.insert(annotations)
|
||||||
.values({
|
.values({
|
||||||
chart_id,
|
chart_id,
|
||||||
timestamp,
|
timestamp: timestampDate,
|
||||||
label_type,
|
label_type,
|
||||||
geometry: geometry || null,
|
geometry: geometry || null,
|
||||||
color: color || '#3b82f6',
|
color: color || '#3b82f6',
|
||||||
})
|
})
|
||||||
.returning();
|
.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) {
|
} catch (error: any) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: error.message || 'Failed to create annotation' },
|
{ error: error.message || 'Failed to create annotation' },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue