import { NextResponse } from 'next/server';
import { PrismaClient } from '@/app/generated/prisma';

export async function POST(request: Request) {
  const prisma = new PrismaClient();
  try {
    const body = await request.json();
    const id: string | undefined = body?.id;
    const approve: boolean | undefined = body?.approve;
    if (!id || typeof approve !== 'boolean') {
      return NextResponse.json({ error: 'id와 approve(boolean)가 필요합니다' }, { status: 400 });
    }

    const updated = await prisma.userHandle.update({
      where: { id },
      data: { isApproved: approve },
      select: { id: true, isApproved: true },
    });

    return NextResponse.json({ ok: true, item: updated });
  } catch (e) {
    console.error('POST /api/admin/user_handles/approve 오류:', e);
    return NextResponse.json({ error: '업데이트 실패' }, { status: 500 });
  } finally {
    await prisma.$disconnect();
  }
}


