Add database and Prisma configurations, enhance event and leaderboard components with API integration, and update navigation for session management

This commit is contained in:
Julien Froidefond
2025-12-09 08:24:14 +01:00
parent f57a30eb4d
commit 4486f305f2
41 changed files with 9094 additions and 167 deletions

View File

@@ -0,0 +1,76 @@
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { Role } from "@/prisma/generated/prisma/client";
export async function GET() {
try {
const session = await auth();
if (!session?.user || session.user.role !== Role.ADMIN) {
return NextResponse.json({ error: "Accès refusé" }, { status: 403 });
}
// Récupérer toutes les préférences utilisateur
const preferences = await prisma.userPreferences.findMany({
include: {
user: {
select: {
id: true,
username: true,
email: true,
},
},
},
});
return NextResponse.json(preferences);
} catch (error) {
console.error("Error fetching admin preferences:", error);
return NextResponse.json(
{ error: "Erreur lors de la récupération des préférences" },
{ status: 500 }
);
}
}
export async function PUT(request: Request) {
try {
const session = await auth();
if (!session?.user || session.user.role !== Role.ADMIN) {
return NextResponse.json({ error: "Accès refusé" }, { status: 403 });
}
const body = await request.json();
const { userId, homeBackground, eventsBackground, leaderboardBackground } =
body;
if (!userId) {
return NextResponse.json({ error: "userId requis" }, { status: 400 });
}
const preferences = await prisma.userPreferences.upsert({
where: { userId },
update: {
homeBackground: homeBackground ?? undefined,
eventsBackground: eventsBackground ?? undefined,
leaderboardBackground: leaderboardBackground ?? undefined,
},
create: {
userId,
homeBackground: homeBackground ?? null,
eventsBackground: eventsBackground ?? null,
leaderboardBackground: leaderboardBackground ?? null,
},
});
return NextResponse.json(preferences);
} catch (error) {
console.error("Error updating admin preferences:", error);
return NextResponse.json(
{ error: "Erreur lors de la mise à jour des préférences" },
{ status: 500 }
);
}
}