Refactor API routes and component logic: Remove unused event and user management routes, streamline feedback handling in components, and enhance state management with transitions for improved user experience. Update service layer methods for better organization and maintainability across the application.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m38s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m38s
This commit is contained in:
63
actions/profile/update-profile.ts
Normal file
63
actions/profile/update-profile.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
'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'
|
||||
|
||||
export async function updateProfile(data: {
|
||||
username?: string
|
||||
avatar?: string | null
|
||||
bio?: string | null
|
||||
characterClass?: string | null
|
||||
}) {
|
||||
try {
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user) {
|
||||
return { success: false, error: 'Non authentifié' }
|
||||
}
|
||||
|
||||
const updatedUser = await userService.validateAndUpdateUserProfile(
|
||||
session.user.id,
|
||||
{
|
||||
username: data.username,
|
||||
avatar: data.avatar,
|
||||
bio: data.bio,
|
||||
characterClass: data.characterClass ? (data.characterClass as CharacterClass) : null,
|
||||
},
|
||||
{
|
||||
id: true,
|
||||
email: true,
|
||||
username: true,
|
||||
avatar: true,
|
||||
bio: true,
|
||||
characterClass: true,
|
||||
hp: true,
|
||||
maxHp: true,
|
||||
xp: true,
|
||||
maxXp: true,
|
||||
level: true,
|
||||
score: true,
|
||||
}
|
||||
)
|
||||
|
||||
revalidatePath('/profile')
|
||||
revalidatePath('/')
|
||||
|
||||
return { success: true, data: updatedUser }
|
||||
} catch (error) {
|
||||
console.error('Error updating profile:', error)
|
||||
|
||||
if (error instanceof ValidationError || error instanceof ConflictError) {
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de la mise à jour du profil' }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user