refactor: Userservice
This commit is contained in:
@@ -1,6 +1,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 } from "@/lib/types";
|
||||
|
||||
const COOKIE_NAME = "peakSkills_userId";
|
||||
@@ -18,8 +18,7 @@ export async function GET() {
|
||||
return NextResponse.json({ user: null }, { status: 200 });
|
||||
}
|
||||
|
||||
const evaluationService = new EvaluationService();
|
||||
const userProfile = await evaluationService.getUserByUuid(userUuid);
|
||||
const userProfile = await userService.getUserByUuid(userUuid);
|
||||
|
||||
if (!userProfile) {
|
||||
// Cookie invalide, le supprimer
|
||||
@@ -52,8 +51,6 @@ export async function POST(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
const evaluationService = new EvaluationService();
|
||||
|
||||
// Vérifier s'il y a déjà un cookie d'authentification
|
||||
const cookieStore = await cookies();
|
||||
const existingUserUuid = cookieStore.get(COOKIE_NAME)?.value;
|
||||
@@ -62,11 +59,11 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
if (existingUserUuid) {
|
||||
// Mettre à jour l'utilisateur existant
|
||||
await evaluationService.updateUserByUuid(existingUserUuid, profile);
|
||||
await userService.updateUserByUuid(existingUserUuid, profile);
|
||||
userUuid = existingUserUuid;
|
||||
} else {
|
||||
// Créer un nouvel utilisateur
|
||||
userUuid = await evaluationService.upsertUserUuid(profile);
|
||||
userUuid = await userService.upsertUserUuid(profile);
|
||||
}
|
||||
|
||||
// Créer la réponse avec le cookie
|
||||
|
||||
Reference in New Issue
Block a user