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,45 +1,47 @@
'use server'
"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'
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
}) {
export async function createFeedback(
eventId: string,
data: {
rating: number;
comment?: string | null;
}
) {
try {
const session = await auth()
const session = await auth();
if (!session?.user?.id) {
return { success: false, error: 'Non authentifié' }
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')
revalidatePath(`/feedback/${eventId}`);
revalidatePath("/events");
return { success: true, data: feedback }
return { success: true, data: feedback };
} catch (error) {
console.error('Error saving feedback:', error)
console.error("Error saving feedback:", error);
if (error instanceof ValidationError) {
return { success: false, error: error.message }
return { success: false, error: error.message };
}
if (error instanceof NotFoundError) {
return { success: false, error: error.message }
return { success: false, error: error.message };
}
return { success: false, error: 'Erreur lors de l\'enregistrement du feedback' }
return {
success: false,
error: "Erreur lors de l'enregistrement du feedback",
};
}
}

View File

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