Refactor event handling and user management: Replace direct database calls with service layer methods for events, user profiles, and preferences, enhancing code organization and maintainability. Update API routes to utilize new services for event registration, feedback, and user statistics, ensuring a consistent approach across the application.

This commit is contained in:
Julien Froidefond
2025-12-12 16:19:13 +01:00
parent fd095246a3
commit 494ac3f503
34 changed files with 1795 additions and 1096 deletions

View File

@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { sitePreferencesService } from "@/services/preferences/site-preferences.service";
import { Role } from "@/prisma/generated/prisma/client";
export async function GET() {
@@ -11,22 +11,8 @@ export async function GET() {
return NextResponse.json({ error: "Accès refusé" }, { status: 403 });
}
// Récupérer les préférences globales du site
let sitePreferences = await prisma.sitePreferences.findUnique({
where: { id: "global" },
});
// Si elles n'existent pas, créer une entrée par défaut
if (!sitePreferences) {
sitePreferences = await prisma.sitePreferences.create({
data: {
id: "global",
homeBackground: null,
eventsBackground: null,
leaderboardBackground: null,
},
});
}
// Récupérer les préférences globales du site (ou créer si elles n'existent pas)
const sitePreferences = await sitePreferencesService.getOrCreateSitePreferences();
return NextResponse.json(sitePreferences);
} catch (error) {
@@ -49,26 +35,10 @@ export async function PUT(request: Request) {
const body = await request.json();
const { homeBackground, eventsBackground, leaderboardBackground } = body;
const preferences = await prisma.sitePreferences.upsert({
where: { id: "global" },
update: {
homeBackground:
homeBackground === "" ? null : (homeBackground ?? undefined),
eventsBackground:
eventsBackground === "" ? null : (eventsBackground ?? undefined),
leaderboardBackground:
leaderboardBackground === ""
? null
: (leaderboardBackground ?? undefined),
},
create: {
id: "global",
homeBackground: homeBackground === "" ? null : (homeBackground ?? null),
eventsBackground:
eventsBackground === "" ? null : (eventsBackground ?? null),
leaderboardBackground:
leaderboardBackground === "" ? null : (leaderboardBackground ?? null),
},
const preferences = await sitePreferencesService.updateSitePreferences({
homeBackground,
eventsBackground,
leaderboardBackground,
});
return NextResponse.json(preferences);