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:
45
actions/events/feedback.ts
Normal file
45
actions/events/feedback.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { auth } from '@/lib/auth'
|
||||
import { eventFeedbackService } from '@/services/events/event-feedback.service'
|
||||
import {
|
||||
ValidationError,
|
||||
NotFoundError,
|
||||
} from '@/services/errors'
|
||||
|
||||
export async function createFeedback(eventId: string, data: {
|
||||
rating: number
|
||||
comment?: string | null
|
||||
}) {
|
||||
try {
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non authentifié' }
|
||||
}
|
||||
|
||||
const feedback = await eventFeedbackService.validateAndCreateFeedback(
|
||||
session.user.id,
|
||||
eventId,
|
||||
{ rating: data.rating, comment: data.comment }
|
||||
)
|
||||
|
||||
revalidatePath(`/feedback/${eventId}`)
|
||||
revalidatePath('/events')
|
||||
|
||||
return { success: true, data: feedback }
|
||||
} catch (error) {
|
||||
console.error('Error saving feedback:', error)
|
||||
|
||||
if (error instanceof ValidationError) {
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
if (error instanceof NotFoundError) {
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
|
||||
return { success: false, error: 'Erreur lors de l\'enregistrement du feedback' }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user