fix: convert timestamp columns to Unix epoch seconds in candles and annotations API
This commit is contained in:
parent
a9bfe36e47
commit
04a8303f4f
2 changed files with 12 additions and 2 deletions
|
|
@ -23,7 +23,12 @@ export async function GET(request: NextRequest) {
|
||||||
.from(annotations)
|
.from(annotations)
|
||||||
.where(eq(annotations.chart_id, parseInt(chartId, 10)));
|
.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) {
|
} catch (error: any) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: error.message || 'Failed to fetch annotations' },
|
{ error: error.message || 'Failed to fetch annotations' },
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,12 @@ export async function GET(request: NextRequest) {
|
||||||
.where(eq(candles.chart_id, parseInt(chartId, 10)))
|
.where(eq(candles.chart_id, parseInt(chartId, 10)))
|
||||||
.orderBy(asc(candles.time));
|
.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) {
|
} catch (error: any) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: error.message || 'Failed to fetch candles' },
|
{ error: error.message || 'Failed to fetch candles' },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue