import { NextRequest, NextResponse } from 'next/server'; import { upsertFirmInstrumentConfig } from '@/lib/db'; export async function PUT( req: NextRequest, { params }: { params: Promise<{ id: string; instrumentId: string }> } ) { const { id: idStr, instrumentId: instrIdStr } = await params; const firmId = parseInt(idStr, 10); const instrumentId = parseInt(instrIdStr, 10); if (isNaN(firmId) || isNaN(instrumentId)) { return NextResponse.json({ error: 'Invalid id' }, { status: 400 }); } const body = await req.json() as { allinFee?: number; roundtripFee?: number; banned?: boolean; }; if ( typeof body.allinFee !== 'number' || typeof body.roundtripFee !== 'number' || typeof body.banned !== 'boolean' ) { return NextResponse.json({ error: 'Invalid body' }, { status: 400 }); } try { upsertFirmInstrumentConfig(firmId, instrumentId, { allinFee: body.allinFee, roundtripFee: body.roundtripFee, banned: body.banned, }); return NextResponse.json({ success: true }); } catch (err) { console.error('[PUT /api/firms/:id/instrument-configs/:instrumentId]', err); return NextResponse.json({ error: 'Failed to save config' }, { status: 500 }); } }