import { NextRequest, NextResponse } from "next/server"; import { auth } from "@/auth"; import { db } from "@/lib/db"; export async function GET( req: NextRequest, { params }: { params: Promise<{ clientId: string }> } ) { const session = await auth(); if (!session?.user) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } const { clientId } = await params; const client = await db.client.findUnique({ where: { id: clientId }, include: { projects: { orderBy: { createdAt: "desc" }, include: { _count: { select: { shots: true } }, }, }, }, }); if (!client) { return NextResponse.json({ error: "Client not found" }, { status: 404 }); } return NextResponse.json({ client }); } export async function PATCH( req: NextRequest, { params }: { params: Promise<{ clientId: string }> } ) { const session = await auth(); if (!session?.user) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } if (!["ADMIN", "PRODUCER"].includes(session.user.role as string)) { return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } const { clientId } = await params; const body = await req.json(); const { company, contactPerson, email, phone, notes, isActive } = body; const client = await db.client.update({ where: { id: clientId }, data: { company, contactPerson, email, phone, notes, isActive }, }); return NextResponse.json({ client }); }