import { withUser, parseBody, json } from "@/lib/api"; import { arenaRetractVoteSchema, arenaVoteSchema } from "@/lib/chat/schemas"; import { castArenaVote, retractArenaVote } from "@/lib/arena/service"; import { LIMITS } from "@/lib/rate-limit"; export const dynamic = "force-dynamic"; /** * POST /api/arena/vote { sessionId, responseId, criterion, category? } * → { votes, ratings } — upserts the vote for (session, criterion); legacy ratings mirrored. */ export const POST = withUser( async ({ req, user }) => { const body = await parseBody(req, arenaVoteSchema); return json(await castArenaVote(user.id, body)); }, { limit: { max: 120, windowMs: 60_000, key: "arena-vote" } }, ); /** DELETE /api/arena/vote { sessionId, criterion } → { votes, ratings } — retracts the vote. */ export const DELETE = withUser( async ({ req, user }) => { const body = await parseBody(req, arenaRetractVoteSchema); return json(await retractArenaVote(user.id, body)); }, { limit: { max: LIMITS.arena.max * 6, windowMs: LIMITS.arena.windowMs, key: "arena-vote" } }, );