chore(api): add explicit type casting for request payloads

This commit is contained in:
jessy-david-dev
2026-04-11 15:20:29 +02:00
parent 7d1b236b46
commit d5a66c2dac
13 changed files with 204 additions and 96 deletions
+3 -3
View File
@@ -3,10 +3,10 @@ import { prisma } from "../../../../../lib/prisma";
type Params = { params: Promise<{ id: string }> };
// PATCH /api/admin/daily/[id] modifier un puzzle
// PATCH /api/admin/daily/[id] - modifier un puzzle
export async function PATCH(req: Request, { params }: Params) {
const { id } = await params;
const { startArticle, targetArticle } = await req.json() as {
const { startArticle, targetArticle } = (await req.json()) as {
startArticle: string;
targetArticle: string;
};
@@ -17,7 +17,7 @@ export async function PATCH(req: Request, { params }: Params) {
return NextResponse.json(puzzle);
}
// DELETE /api/admin/daily/[id] supprimer un puzzle
// DELETE /api/admin/daily/[id] - supprimer un puzzle
export async function DELETE(_req: Request, { params }: Params) {
const { id } = await params;
await prisma.dailyPuzzle.delete({ where: { id } });
+3 -3
View File
@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { prisma } from "../../../../lib/prisma";
// GET /api/admin/daily liste tous les puzzles
// GET /api/admin/daily - liste tous les puzzles
export async function GET() {
const puzzles = await prisma.dailyPuzzle.findMany({
orderBy: { date: "desc" },
@@ -11,9 +11,9 @@ export async function GET() {
return NextResponse.json(puzzles);
}
// POST /api/admin/daily créer un puzzle pour une date
// POST /api/admin/daily - créer un puzzle pour une date
export async function POST(req: Request) {
const { date, startArticle, targetArticle } = await req.json() as {
const { date, startArticle, targetArticle } = (await req.json()) as {
date: string;
startArticle: string;
targetArticle: string;
+49 -42
View File
@@ -10,48 +10,55 @@ export async function GET() {
const since14 = new Date(todayStart);
since14.setDate(since14.getDate() - 13);
const [totalUsers, totalGames, todayGames, recentUsers, recentGames, modeStats, activityRaw] =
await Promise.all([
prisma.user.count(),
prisma.game.count(),
prisma.game.count({ where: { playedAt: { gte: todayStart } } }),
prisma.user.findMany({
orderBy: { createdAt: "desc" },
take: 50,
select: {
id: true,
name: true,
email: true,
banned: true,
createdAt: true,
_count: { select: { games: true } },
},
}),
prisma.game.findMany({
orderBy: { playedAt: "desc" },
take: 50,
select: {
id: true,
mode: true,
startArticle: true,
targetArticle: true,
clicks: true,
timeSeconds: true,
won: true,
playedAt: true,
user: { select: { name: true } },
},
}),
prisma.game.groupBy({
by: ["mode"],
_count: { id: true },
_avg: { clicks: true, timeSeconds: true },
}),
prisma.game.findMany({
where: { playedAt: { gte: since14 } },
select: { playedAt: true },
}),
]);
const [
totalUsers,
totalGames,
todayGames,
recentUsers,
recentGames,
modeStats,
activityRaw,
] = await Promise.all([
prisma.user.count(),
prisma.game.count(),
prisma.game.count({ where: { playedAt: { gte: todayStart } } }),
prisma.user.findMany({
orderBy: { createdAt: "desc" },
take: 50,
select: {
id: true,
name: true,
email: true,
banned: true,
createdAt: true,
_count: { select: { games: true } },
},
}),
prisma.game.findMany({
orderBy: { playedAt: "desc" },
take: 50,
select: {
id: true,
mode: true,
startArticle: true,
targetArticle: true,
clicks: true,
timeSeconds: true,
won: true,
playedAt: true,
user: { select: { name: true } },
},
}),
prisma.game.groupBy({
by: ["mode"],
_count: { id: true },
_avg: { clicks: true, timeSeconds: true },
}),
prisma.game.findMany({
where: { playedAt: { gte: since14 } },
select: { playedAt: true },
}),
]);
// Agréger l'activité par jour
const activityMap = new Map<string, number>();
+3 -3
View File
@@ -3,17 +3,17 @@ import { prisma } from "../../../../../lib/prisma";
type Params = { params: Promise<{ id: string }> };
// DELETE /api/admin/users/[id] supprimer un utilisateur
// 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
// 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 { 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 });
}