feat: handling SSR on evaluation

This commit is contained in:
Julien Froidefond
2025-08-21 13:19:46 +02:00
parent 69f23db55d
commit ef16c73625
7 changed files with 481 additions and 135 deletions

View File

@@ -1,28 +1,40 @@
import { NextRequest, NextResponse } from "next/server";
import { cookies } from "next/headers";
import { evaluationService } from "@/services/evaluation-service";
import { UserProfile, SkillLevel } from "@/lib/types";
const COOKIE_NAME = "peakSkills_userId";
export async function PUT(request: NextRequest) {
try {
const body = await request.json();
const {
profile,
category,
skillId,
level,
canMentor,
wantsToLearn,
action,
} = body;
// Récupérer l'utilisateur depuis le cookie
const cookieStore = await cookies();
const userId = cookieStore.get(COOKIE_NAME)?.value;
if (!profile || !category || !skillId) {
if (!userId) {
return NextResponse.json(
{ error: "profile, category et skillId sont requis" },
{ status: 400 }
{ error: "Utilisateur non authentifié" },
{ status: 401 }
);
}
const userProfile: UserProfile = profile;
const userProfile = await evaluationService.getUserById(parseInt(userId));
if (!userProfile) {
return NextResponse.json(
{ error: "Utilisateur introuvable" },
{ status: 404 }
);
}
const body = await request.json();
const { category, skillId, level, canMentor, wantsToLearn, action } = body;
if (!category || !skillId) {
return NextResponse.json(
{ error: "category et skillId sont requis" },
{ status: 400 }
);
}
switch (action) {
case "updateLevel":