feat: handling SSR on evaluation
This commit is contained in:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user