Refactor event status handling: Remove EventStatus enum from the Prisma schema and update related API routes and UI components to calculate event status dynamically based on event date. This change simplifies event management and enhances data integrity by ensuring status is always derived from the date.

This commit is contained in:
Julien Froidefond
2025-12-10 05:45:25 +01:00
parent fb830c6fcc
commit a69613a232
15 changed files with 167 additions and 298 deletions

28
lib/eventStatus.ts Normal file
View File

@@ -0,0 +1,28 @@
/**
* Calcule le statut d'un événement en fonction de sa date
* @param eventDate La date de l'événement
* @returns Le statut calculé (PAST, LIVE, ou UPCOMING)
*/
export function calculateEventStatus(
eventDate: Date | string
): "UPCOMING" | "LIVE" | "PAST" {
const date = typeof eventDate === "string" ? new Date(eventDate) : eventDate;
const now = new Date();
// Normaliser les dates à minuit UTC pour comparer uniquement les jours
const eventDateOnly = new Date(
Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())
);
const todayOnly = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
);
if (eventDateOnly < todayOnly) {
return "PAST";
} else if (eventDateOnly.getTime() === todayOnly.getTime()) {
return "LIVE";
} else {
return "UPCOMING";
}
}