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

View File

@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { Role, EventType, EventStatus } from "@/prisma/generated/prisma/client";
import { Role, EventType } from "@/prisma/generated/prisma/client";
export async function PUT(
request: Request,
@@ -16,7 +16,8 @@ export async function PUT(
const { id } = await params;
const body = await request.json();
const { date, name, description, type, status, room, time, maxPlaces } = body;
const { date, name, description, type, room, time, maxPlaces } = body;
// Le statut est ignoré s'il est fourni, il sera calculé automatiquement
// Vérifier que l'événement existe
const existingEvent = await prisma.event.findUnique({
@@ -35,7 +36,6 @@ export async function PUT(
name?: string;
description?: string;
type?: EventType;
status?: EventStatus;
room?: string | null;
time?: string | null;
maxPlaces?: number | null;
@@ -62,18 +62,11 @@ export async function PUT(
}
updateData.type = type as EventType;
}
if (status !== undefined) {
if (!Object.values(EventStatus).includes(status)) {
return NextResponse.json(
{ error: "Statut d'événement invalide" },
{ status: 400 }
);
}
updateData.status = status as EventStatus;
}
// Le statut est toujours calculé automatiquement, on ignore s'il est fourni
if (room !== undefined) updateData.room = room || null;
if (time !== undefined) updateData.time = time || null;
if (maxPlaces !== undefined) updateData.maxPlaces = maxPlaces ? parseInt(maxPlaces) : null;
if (maxPlaces !== undefined)
updateData.maxPlaces = maxPlaces ? parseInt(maxPlaces) : null;
const event = await prisma.event.update({
where: { id },
@@ -128,4 +121,3 @@ export async function DELETE(
);
}
}