refactor: remove legacy evaluation route and update user management interfaces
- Deleted the obsolete evaluations route to streamline the API. - Added User and UserFormData interfaces to admin-client for better user management. - Updated useUsersManagement hook to utilize adminClient for fetching and creating users, improving data handling. - Cleaned up unused imports and code for better maintainability.
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
import { evaluationService } from "@/services/evaluation-service";
|
||||
import { userService } from "@/services/user-service";
|
||||
import { UserEvaluation, UserProfile } from "@/lib/types";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const cookieStore = await cookies();
|
||||
const userUuid = cookieStore.get("peakSkills_userId")?.value;
|
||||
|
||||
// Support pour l'ancien mode avec paramètres (pour la compatibilité)
|
||||
if (!userUuid) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const firstName = searchParams.get("firstName");
|
||||
const lastName = searchParams.get("lastName");
|
||||
const teamId = searchParams.get("teamId");
|
||||
|
||||
if (!firstName || !lastName || !teamId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Utilisateur non authentifié" },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
const profile: UserProfile = { firstName, lastName, teamId };
|
||||
const evaluation = await evaluationService.loadUserEvaluation(profile);
|
||||
return NextResponse.json({ evaluation });
|
||||
}
|
||||
|
||||
// Mode authentifié par cookie UUID
|
||||
const userProfile = await userService.getUserByUuid(userUuid);
|
||||
if (!userProfile) {
|
||||
return NextResponse.json(
|
||||
{ error: "Utilisateur non trouvé" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
const evaluation = await evaluationService.loadUserEvaluation(userProfile);
|
||||
return NextResponse.json({ evaluation });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement de l'évaluation:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur interne du serveur" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const evaluation: UserEvaluation = body.evaluation;
|
||||
|
||||
if (!evaluation || !evaluation.profile) {
|
||||
return NextResponse.json(
|
||||
{ error: "Évaluation invalide" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
await evaluationService.saveUserEvaluation(evaluation);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la sauvegarde de l'évaluation:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur interne du serveur" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
import { evaluationService } from "@/services/evaluation-service";
|
||||
import { userService } from "@/services/user-service";
|
||||
import { UserProfile, SkillLevel } from "@/lib/types";
|
||||
|
||||
const COOKIE_NAME = "peakSkills_userId";
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { SkillsService } from "@/services";
|
||||
import { SkillCategory } from "@/lib/types";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
|
||||
@@ -25,6 +25,20 @@ export interface TeamMember {
|
||||
joinedAt: string;
|
||||
}
|
||||
|
||||
export interface UserFormData {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamId: string;
|
||||
}
|
||||
|
||||
export interface User {
|
||||
uuid: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamName?: string;
|
||||
hasEvaluations: boolean;
|
||||
}
|
||||
|
||||
export class AdminClient extends BaseHttpClient {
|
||||
// Skills Management
|
||||
async getSkills(): Promise<Skill[]> {
|
||||
@@ -80,6 +94,14 @@ export class AdminClient extends BaseHttpClient {
|
||||
}
|
||||
|
||||
// User Management
|
||||
async getUsers(): Promise<User[]> {
|
||||
return await this.get<User[]>(`/admin/users`);
|
||||
}
|
||||
|
||||
async createUser(userData: UserFormData): Promise<User> {
|
||||
return await this.post<User>(`/admin/users`, userData);
|
||||
}
|
||||
|
||||
async deleteUser(userId: string): Promise<void> {
|
||||
await this.delete(`/admin/users/${userId}`);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { Team } from "@/lib/types";
|
||||
|
||||
interface User {
|
||||
uuid: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamName?: string;
|
||||
hasEvaluations: boolean;
|
||||
}
|
||||
|
||||
interface UserFormData {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
teamId: string;
|
||||
}
|
||||
import { adminClient } from "@/clients";
|
||||
import { User, UserFormData } from "@/clients/domains/admin-client";
|
||||
|
||||
export function useUsersManagement(teams: Team[]) {
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
@@ -34,11 +22,7 @@ export function useUsersManagement(teams: Team[]) {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/admin/users");
|
||||
if (!response.ok) {
|
||||
throw new Error("Erreur lors de la récupération des utilisateurs");
|
||||
}
|
||||
const usersData = await response.json();
|
||||
const usersData = await adminClient.getUsers();
|
||||
setUsers(usersData);
|
||||
} catch (err: any) {
|
||||
setError(err.message || "Erreur lors du chargement des utilisateurs");
|
||||
@@ -68,7 +52,7 @@ export function useUsersManagement(teams: Team[]) {
|
||||
|
||||
try {
|
||||
setIsSubmitting(true);
|
||||
// TODO: Implémenter la création d'utilisateur
|
||||
await adminClient.createUser(userFormData);
|
||||
toast({
|
||||
title: "Succès",
|
||||
description: "Utilisateur créé avec succès",
|
||||
@@ -112,8 +96,7 @@ export function useUsersManagement(teams: Team[]) {
|
||||
|
||||
setDeletingUserId(user.uuid);
|
||||
try {
|
||||
// TODO: Implémenter la suppression d'utilisateur
|
||||
// await adminClient.deleteUser(user.uuid);
|
||||
await adminClient.deleteUser(user.uuid);
|
||||
|
||||
// Mettre à jour la liste locale
|
||||
setUsers((prev) => prev.filter((u) => u.uuid !== user.uuid));
|
||||
|
||||
Reference in New Issue
Block a user