import { getSession } from '@/lib/session' import { isAdmin } from '@/lib/admin' import { createForum } from '@/lib/admin-forum' export async function POST(request: Request) { const session = await getSession() if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 }) let b: Record = {} try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) } const categoryId = Number(b.categoryId) const name = String(b.name ?? '').trim() const description = String(b.description ?? '').trim() const order = Number(b.order) || 0 const visibility = b.visibility === false ? 0 : 1 if (!categoryId || !name) return Response.json({ success: false, error: 'emptyError' }) const id = await createForum(categoryId, name, description, order, visibility) return Response.json({ success: true, id }) }