import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { requirePermission } from "@/lib/rbac";
import { getUserIdFromRequest } from "@/lib/auth";

export async function POST(req: Request, context: { params: Promise<{ id: string }> }) {
  const { id } = await context.params;
  const userId = getUserIdFromRequest(req);
  try {
    await requirePermission({ userId, resource: "BOARD", action: "MODERATE" });
  } catch (e: any) {
    return NextResponse.json({ error: "Forbidden" }, { status: 403 });
  }
  const post = await prisma.post.update({
    where: { id },
    data: { status: "published" },
    select: { id: true, status: true },
  });
  return NextResponse.json({ post });
}


