32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { assertChannelRoomAccess } from '@/lib/auth/room-access';
|
|
import { addDice, getRoom, notifyRoom, toPublicRoom } from '@/lib/rooms/store';
|
|
|
|
export const runtime = 'nodejs';
|
|
|
|
type Params = { params: Promise<{ roomId: string }> };
|
|
|
|
export async function POST(request: Request, { params }: Params) {
|
|
const { roomId } = await params;
|
|
const room = getRoom(roomId);
|
|
if (!room) {
|
|
return NextResponse.json({ error: '방을 찾을 수 없습니다.' }, { status: 404 });
|
|
}
|
|
|
|
const access = await assertChannelRoomAccess(room, request);
|
|
if (!access.ok) return access.response;
|
|
|
|
const body = (await request.json().catch(() => ({}))) as { count?: number };
|
|
const count = Number(body.count ?? 1);
|
|
if (!Number.isFinite(count) || count < 1) {
|
|
return NextResponse.json({ error: 'count는 1 이상이어야 합니다.' }, { status: 400 });
|
|
}
|
|
|
|
const updated = addDice(roomId, count);
|
|
if (!updated) {
|
|
return NextResponse.json({ error: '처리 실패' }, { status: 500 });
|
|
}
|
|
notifyRoom(roomId);
|
|
return NextResponse.json({ room: toPublicRoom(updated) });
|
|
}
|