Fix Supabase column mapping

This commit is contained in:
root
2026-02-23 19:52:27 +00:00
parent 2bb58e041b
commit 8d37ce19d6
+21 -6
View File
@@ -21,19 +21,34 @@ export async function POST(request: NextRequest) {
try {
const body = await request.json()
// Convert camelCase to snake_case for Supabase
const trade = {
pair: body.pair || body.pair,
direction: body.direction,
entry_price: body.entryPrice || body.entry_price,
exit_price: body.exitPrice || body.exit_price,
status: body.status || 'open',
is_demo: body.isDemo ?? body.is_demo ?? true,
trader_style: body.traderStyle || body.trader_style,
setup: body.setup,
timeframe: body.timeframe,
pnl: body.pnl,
opened_at: new Date().toISOString(),
}
const { data, error } = await supabase
.from('trades')
.insert([{
...body,
opened_at: new Date().toISOString(),
}])
.insert([trade])
.select()
if (error) throw error
if (error) {
console.error('Supabase insert error:', error)
return NextResponse.json({ error: error.message }, { status: 500 })
}
return NextResponse.json({ success: true, trade: data?.[0] })
} catch (error) {
console.error('Supabase error:', error)
console.error('Error:', error)
return NextResponse.json({ error: 'Failed to save' }, { status: 500 })
}
}