route.ts
963 bytes
| 1 | import { NextResponse } from 'next/server'; |
|---|---|
| 2 | import { currentUserId } from '@/auth'; |
| 3 | import { getDebateOwnership } from '@/db/repositories'; |
| 4 | import { gavelDebate } from '@/lib/debate-registry'; |
| 5 | |
| 6 | export const runtime = 'nodejs'; |
| 7 | |
| 8 | type Params = { params: Promise<{ id: string }> }; |
| 9 | |
| 10 | /** |
| 11 | * POST: conclude a running debate gracefully - skip remaining rounds and go |
| 12 | * straight to synthesis (unlike cancel, which aborts and wastes the spend). |
| 13 | */ |
| 14 | export async function POST(_request: Request, { params }: Params) { |
| 15 | const { id } = await params; |
| 16 | const ownership = await getDebateOwnership(id); |
| 17 | if (!ownership) return NextResponse.json({ error: 'Not found' }, { status: 404 }); |
| 18 | |
| 19 | const userId = await currentUserId(); |
| 20 | const canControl = ownership.userId === null || ownership.userId === userId; |
| 21 | if (!canControl) return NextResponse.json({ error: 'Forbidden' }, { status: 403 }); |
| 22 | |
| 23 | const struck = gavelDebate(id); |
| 24 | return NextResponse.json({ ok: struck }); |
| 25 | } |
| 26 | |