fix: normalize span annotation timestamps to Unix epoch seconds in all API responses
This commit is contained in:
parent
900443d078
commit
c404e79678
2 changed files with 22 additions and 3 deletions
|
|
@ -42,7 +42,13 @@ export async function PATCH(
|
|||
.where(eq(spanAnnotations.id, parseInt(id)))
|
||||
.returning();
|
||||
|
||||
return NextResponse.json(result[0]);
|
||||
const s = result[0];
|
||||
return NextResponse.json({
|
||||
...s,
|
||||
start_time: s.start_time instanceof Date ? Math.floor(s.start_time.getTime() / 1000) : s.start_time,
|
||||
end_time: s.end_time instanceof Date ? Math.floor(s.end_time.getTime() / 1000) : s.end_time,
|
||||
created_at: s.created_at instanceof Date ? Math.floor(s.created_at.getTime() / 1000) : s.created_at,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('Error updating span annotation:', error);
|
||||
return NextResponse.json(
|
||||
|
|
|
|||
|
|
@ -22,7 +22,14 @@ export async function GET(request: NextRequest) {
|
|||
.where(eq(spanAnnotations.chart_id, parseInt(chartId)))
|
||||
.orderBy(desc(spanAnnotations.start_time));
|
||||
|
||||
return NextResponse.json(spans);
|
||||
const normalized = spans.map((s) => ({
|
||||
...s,
|
||||
start_time: s.start_time instanceof Date ? Math.floor(s.start_time.getTime() / 1000) : s.start_time,
|
||||
end_time: s.end_time instanceof Date ? Math.floor(s.end_time.getTime() / 1000) : s.end_time,
|
||||
created_at: s.created_at instanceof Date ? Math.floor(s.created_at.getTime() / 1000) : s.created_at,
|
||||
}));
|
||||
|
||||
return NextResponse.json(normalized);
|
||||
} catch (error) {
|
||||
console.error('Error fetching span annotations:', error);
|
||||
return NextResponse.json(
|
||||
|
|
@ -78,7 +85,13 @@ export async function POST(request: NextRequest) {
|
|||
})
|
||||
.returning();
|
||||
|
||||
return NextResponse.json(result[0], { status: 201 });
|
||||
const s = result[0];
|
||||
return NextResponse.json({
|
||||
...s,
|
||||
start_time: s.start_time instanceof Date ? Math.floor(s.start_time.getTime() / 1000) : s.start_time,
|
||||
end_time: s.end_time instanceof Date ? Math.floor(s.end_time.getTime() / 1000) : s.end_time,
|
||||
created_at: s.created_at instanceof Date ? Math.floor(s.created_at.getTime() / 1000) : s.created_at,
|
||||
}, { status: 201 });
|
||||
} catch (error: any) {
|
||||
console.error('Error creating span annotation:', error);
|
||||
return NextResponse.json(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue