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:
65
actions/events/register.ts
Normal file
65
actions/events/register.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { eventRegistrationService } from '@/services/events/event-registration.service'
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
ConflictError,
|
||||
} from '@/services/errors'
|
||||
|
||||
export async function registerForEvent(eventId: string) {
|
||||
try {
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté pour vous inscrire' }
|
||||
}
|
||||
|
||||
const registration = await eventRegistrationService.validateAndRegisterUser(
|
||||
session.user.id,
|
||||
eventId
|
||||
)
|
||||
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
|
||||
return { success: true, message: 'Inscription réussie', data: registration }
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error)
|
||||
|
||||
if (error instanceof ValidationError || error instanceof ConflictError) {
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
|
||||
return { success: false, error: 'Une erreur est survenue lors de l\'inscription' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function unregisterFromEvent(eventId: string) {
|
||||
try {
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Vous devez être connecté' }
|
||||
}
|
||||
|
||||
await eventRegistrationService.unregisterUserFromEvent(
|
||||
session.user.id,
|
||||
eventId
|
||||
)
|
||||
|
||||
revalidatePath('/events')
|
||||
revalidatePath('/')
|
||||
|
||||
return { success: true, message: 'Inscription annulée' }
|
||||
} catch (error) {
|
||||
console.error('Unregistration error:', error)
|
||||
return { success: false, error: 'Une erreur est survenue lors de l\'annulation' }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user