Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.next
.env*.local
tsconfig.tsbuildinfo
15 changes: 13 additions & 2 deletions app/api/sessions/[id]/rounds/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ export async function POST(req: Request, { params }: { params: { id: string } })
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 });

// Ensure there is no active round for this session
const activeRound = await sql`
SELECT id FROM rounds WHERE session_id = ${id} AND status = 'active'
`;
if (activeRound.length > 0) {
return NextResponse.json(
{ error: 'A round is already active for this session. End the current round before starting a new one.' },
{ status: 409 }
);
}

// Update session status to active
await sql`UPDATE sessions SET status = 'active' WHERE id = ${id}`;

Expand All @@ -30,8 +41,8 @@ export async function POST(req: Request, { params }: { params: { id: string } })

// Create new round
const newRounds = await sql`
INSERT INTO rounds (session_id, round_number, shock_description)
VALUES (${id}, ${nextRoundNumber}, ${shock?.description || null})
INSERT INTO rounds (session_id, round_number, shock_description, status)
VALUES (${id}, ${nextRoundNumber}, ${shock?.description || null}, 'active')
RETURNING id
`;
const roundId = newRounds[0].id;
Expand Down