- Add admin page at /admin (restricted to ADMIN_EMAIL via proxy) - Implement user ban/unban and deletion - Add daily puzzle creation, modification, deletion - Include 14-day activity chart with hover details - Add User.banned field to schema and migrate database - Block banned users from logging in - Add ADMIN_EMAIL to .env.local configuration - Update Prisma client after schema changes
20 lines
747 B
TypeScript
20 lines
747 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { prisma } from "../../../../../lib/prisma";
|
|
|
|
type Params = { params: Promise<{ id: string }> };
|
|
|
|
// DELETE /api/admin/users/[id] — supprimer un utilisateur
|
|
export async function DELETE(_req: Request, { params }: Params) {
|
|
const { id } = await params;
|
|
await prisma.user.delete({ where: { id } });
|
|
return NextResponse.json({ ok: true });
|
|
}
|
|
|
|
// PATCH /api/admin/users/[id] — ban/unban
|
|
export async function PATCH(req: Request, { params }: Params) {
|
|
const { id } = await params;
|
|
const { banned } = await req.json() as { banned: boolean };
|
|
const user = await prisma.user.update({ where: { id }, data: { banned } });
|
|
return NextResponse.json({ id: user.id, banned: user.banned });
|
|
}
|