From 04a8303f4f9927220c8b2e33095a1053001d54e6 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Tue, 17 Feb 2026 19:40:48 +0100 Subject: [PATCH] fix: convert timestamp columns to Unix epoch seconds in candles and annotations API --- src/app/api/annotations/route.ts | 7 ++++++- src/app/api/candles/route.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/api/annotations/route.ts b/src/app/api/annotations/route.ts index 2a49e65..41d8ef1 100644 --- a/src/app/api/annotations/route.ts +++ b/src/app/api/annotations/route.ts @@ -23,7 +23,12 @@ export async function GET(request: NextRequest) { .from(annotations) .where(eq(annotations.chart_id, parseInt(chartId, 10))); - return NextResponse.json(allAnnotations); + const normalized = allAnnotations.map((a) => ({ + ...a, + timestamp: a.timestamp instanceof Date ? Math.floor(a.timestamp.getTime() / 1000) : a.timestamp, + })); + + return NextResponse.json(normalized); } catch (error: any) { return NextResponse.json( { error: error.message || 'Failed to fetch annotations' }, diff --git a/src/app/api/candles/route.ts b/src/app/api/candles/route.ts index cce9088..8c1f734 100644 --- a/src/app/api/candles/route.ts +++ b/src/app/api/candles/route.ts @@ -29,7 +29,12 @@ export async function GET(request: NextRequest) { .where(eq(candles.chart_id, parseInt(chartId, 10))) .orderBy(asc(candles.time)); - return NextResponse.json(allCandles); + const normalized = allCandles.map((c) => ({ + ...c, + time: c.time instanceof Date ? Math.floor(c.time.getTime() / 1000) : c.time, + })); + + return NextResponse.json(normalized); } catch (error: any) { return NextResponse.json( { error: error.message || 'Failed to fetch candles' },