Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/api/sessions/[id]/shocks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ export async function POST(req: Request, { params }: { params: { id: string } })
const { id } = params;
const { passphrase, type, description, priceShift } = await req.json();

if (typeof type !== 'string' || type.trim().length === 0) {
return NextResponse.json({ error: 'type is required and must be a non-empty string' }, { status: 400 });
}
if (typeof description !== 'string' || description.trim().length === 0) {
return NextResponse.json({ error: 'description is required and must be a non-empty string' }, { status: 400 });
}

const shift = typeof priceShift === 'number' && isFinite(priceShift) ? priceShift : 10;

const session = await sql`SELECT * FROM sessions WHERE id = ${id}`;
if (session.length === 0) return NextResponse.json({ error: 'Session not found' }, { status: 404 });
if (session[0].passphrase !== passphrase) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });

await sql`
INSERT INTO shocks (session_id, type, description, price_shift)
VALUES (${id}, ${type}, ${description}, ${priceShift})
VALUES (${id}, ${type}, ${description}, ${shift})
`;

return NextResponse.json({ success: true });
Expand Down