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
Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
This commit is contained in:
@@ -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" };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user