Files
peakskills/app/api/evaluations/skills/route.ts
Julien Froidefond 4e82a6d860 feat: add PostgreSQL support and enhance evaluation loading
- Added `pg` and `@types/pg` dependencies for PostgreSQL integration.
- Updated `useEvaluation` hook to load user evaluations from the API, improving data management.
- Refactored `saveUserEvaluation` and `loadUserEvaluation` functions to interact with the API instead of localStorage.
- Introduced error handling for profile loading and evaluation saving to enhance robustness.
- Added new methods for managing user profiles and evaluations, including `clearUserProfile` and `loadEvaluationForProfile`.
2025-08-21 08:46:52 +02:00

105 lines
2.5 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { evaluationService } from "@/services/evaluation-service";
import { UserProfile, SkillLevel } from "@/lib/types";
export async function PUT(request: NextRequest) {
try {
const body = await request.json();
const {
profile,
category,
skillId,
level,
canMentor,
wantsToLearn,
action,
} = body;
if (!profile || !category || !skillId) {
return NextResponse.json(
{ error: "profile, category et skillId sont requis" },
{ status: 400 }
);
}
const userProfile: UserProfile = profile;
switch (action) {
case "updateLevel":
if (level === undefined) {
return NextResponse.json(
{ error: "level est requis pour updateLevel" },
{ status: 400 }
);
}
await evaluationService.updateSkillLevel(
userProfile,
category,
skillId,
level
);
break;
case "updateMentorStatus":
if (canMentor === undefined) {
return NextResponse.json(
{ error: "canMentor est requis pour updateMentorStatus" },
{ status: 400 }
);
}
await evaluationService.updateSkillMentorStatus(
userProfile,
category,
skillId,
canMentor
);
break;
case "updateLearningStatus":
if (wantsToLearn === undefined) {
return NextResponse.json(
{ error: "wantsToLearn est requis pour updateLearningStatus" },
{ status: 400 }
);
}
await evaluationService.updateSkillLearningStatus(
userProfile,
category,
skillId,
wantsToLearn
);
break;
case "addSkill":
await evaluationService.addSkillToEvaluation(
userProfile,
category,
skillId
);
break;
case "removeSkill":
await evaluationService.removeSkillFromEvaluation(
userProfile,
category,
skillId
);
break;
default:
return NextResponse.json(
{ error: "Action non supportée" },
{ status: 400 }
);
}
return NextResponse.json({ success: true });
} catch (error) {
console.error("Erreur lors de la mise à jour de la skill:", error);
return NextResponse.json(
{ error: "Erreur interne du serveur" },
{ status: 500 }
);
}
}