import { db } from "@/lib/db" import { NextResponse } from "next/server"; import fetchUser from "@/lib/fetch-user"; export async function GET(req: Request) { try { const user = await fetchUser(req) if (!user || user.role != "ADMIN") { return new NextResponse("Unauthorized", { status: 401 }); } const { searchParams } = new URL(req.url) const qn = searchParams.get('qn') as string const id = searchParams.get('id') as string if (qn) { const users = await db.user.findMany({ where: { name: { contains: qn } } }) return NextResponse.json(users) } if (id) { const users = await db.user.findUnique({ where: { id: id } }) return NextResponse.json(users) } const users = await db.user.findMany(); return NextResponse.json(users) } catch (error) { console.log("[AUTH/ACCOUNT/IMPERSONATION]", error); return new NextResponse("Internal Error", { status: 500 }); } }