Refactor admin actions and improve code formatting: Standardize import statements, enhance error handling messages, and apply consistent formatting across event, user, and preference management functions for better readability and maintainability.
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled

This commit is contained in:
Julien Froidefond
2025-12-15 21:20:39 +01:00
parent 321da3176e
commit b790ee21f2
52 changed files with 12712 additions and 8554 deletions

View File

@@ -1,25 +1,22 @@
'use server'
"use server";
import { revalidatePath } from 'next/cache'
import { auth } from '@/lib/auth'
import { userService } from '@/services/users/user.service'
import { CharacterClass } from '@/prisma/generated/prisma/client'
import {
ValidationError,
ConflictError,
} from '@/services/errors'
import { revalidatePath } from "next/cache";
import { auth } from "@/lib/auth";
import { userService } from "@/services/users/user.service";
import { CharacterClass } from "@/prisma/generated/prisma/client";
import { ValidationError, ConflictError } from "@/services/errors";
export async function updateProfile(data: {
username?: string
avatar?: string | null
bio?: string | null
characterClass?: string | null
username?: string;
avatar?: string | null;
bio?: string | null;
characterClass?: string | null;
}) {
try {
const session = await auth()
const session = await auth();
if (!session?.user) {
return { success: false, error: 'Non authentifié' }
return { success: false, error: "Non authentifié" };
}
const updatedUser = await userService.validateAndUpdateUserProfile(
@@ -28,7 +25,9 @@ export async function updateProfile(data: {
username: data.username,
avatar: data.avatar,
bio: data.bio,
characterClass: data.characterClass ? (data.characterClass as CharacterClass) : null,
characterClass: data.characterClass
? (data.characterClass as CharacterClass)
: null,
},
{
id: true,
@@ -44,20 +43,19 @@ export async function updateProfile(data: {
level: true,
score: true,
}
)
);
revalidatePath('/profile')
revalidatePath('/')
revalidatePath("/profile");
revalidatePath("/");
return { success: true, data: updatedUser }
return { success: true, data: updatedUser };
} catch (error) {
console.error('Error updating profile:', error)
console.error("Error updating profile:", error);
if (error instanceof ValidationError || error instanceof ConflictError) {
return { success: false, error: error.message }
return { success: false, error: error.message };
}
return { success: false, error: 'Erreur lors de la mise à jour du profil' }
return { success: false, error: "Erreur lors de la mise à jour du profil" };
}
}