Grapevine_Disease_Detection/vineye-admin/app/api/users/route.ts
Yanis fe70005a86 add vineye-admin dashboard (Next.js)
Admin panel for VinEye with dashboard, users, diseases, guides, alerts management.
Stack: Next.js App Router + Prisma + PostgreSQL + better-auth.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 11:22:01 +02:00

42 lines
1 KiB
TypeScript

import { NextRequest } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireAdmin } from "@/lib/auth-guard";
export async function GET(request: NextRequest) {
const auth = await requireAdmin();
if ("error" in auth) {
return Response.json({ error: auth.error }, { status: auth.status });
}
const { searchParams } = request.nextUrl;
const role = searchParams.get("role");
const search = searchParams.get("search");
const where: Record<string, unknown> = {};
if (role) where.role = role;
if (search) {
where.OR = [
{ name: { contains: search, mode: "insensitive" } },
{ email: { contains: search, mode: "insensitive" } },
];
}
const users = await prisma.user.findMany({
where,
select: {
id: true,
name: true,
email: true,
role: true,
xp: true,
level: true,
banned: true,
createdAt: true,
_count: { select: { scans: true } },
},
orderBy: { createdAt: "desc" },
});
return Response.json({ data: users });
}