Fix Supabase column mapping
This commit is contained in:
@@ -21,19 +21,34 @@ export async function POST(request: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
const body = await request.json()
|
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
|
const { data, error } = await supabase
|
||||||
.from('trades')
|
.from('trades')
|
||||||
.insert([{
|
.insert([trade])
|
||||||
...body,
|
|
||||||
opened_at: new Date().toISOString(),
|
|
||||||
}])
|
|
||||||
.select()
|
.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] })
|
return NextResponse.json({ success: true, trade: data?.[0] })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Supabase error:', error)
|
console.error('Error:', error)
|
||||||
return NextResponse.json({ error: 'Failed to save' }, { status: 500 })
|
return NextResponse.json({ error: 'Failed to save' }, { status: 500 })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user