fix: convert timestamp columns to Unix epoch seconds in candles and annotations API

This commit is contained in:
Marko Djordjevic 2026-02-17 19:40:48 +01:00
parent a9bfe36e47
commit 04a8303f4f
2 changed files with 12 additions and 2 deletions

View file

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

View file

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