Refactor event date handling: Update event model to use DateTime type for date fields in Prisma schema. Modify API routes and UI components to ensure consistent date formatting and handling, improving data integrity and user experience across event management and display.
This commit is contained in:
@@ -31,7 +31,7 @@ export async function PUT(
|
||||
}
|
||||
|
||||
const updateData: {
|
||||
date?: string;
|
||||
date?: Date;
|
||||
name?: string;
|
||||
description?: string;
|
||||
type?: EventType;
|
||||
@@ -41,7 +41,16 @@ export async function PUT(
|
||||
maxPlaces?: number | null;
|
||||
} = {};
|
||||
|
||||
if (date !== undefined) updateData.date = date;
|
||||
if (date !== undefined) {
|
||||
const eventDate = new Date(date);
|
||||
if (isNaN(eventDate.getTime())) {
|
||||
return NextResponse.json(
|
||||
{ error: "Format de date invalide" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
updateData.date = eventDate;
|
||||
}
|
||||
if (name !== undefined) updateData.name = name;
|
||||
if (description !== undefined) updateData.description = description;
|
||||
if (type !== undefined) {
|
||||
|
||||
@@ -38,7 +38,7 @@ export async function GET() {
|
||||
// Transformer les données pour inclure le nombre d'inscriptions
|
||||
const eventsWithCount = events.map((event) => ({
|
||||
id: event.id,
|
||||
date: event.date,
|
||||
date: event.date.toISOString(),
|
||||
name: event.name,
|
||||
description: event.description,
|
||||
type: event.type,
|
||||
@@ -96,7 +96,7 @@ export async function POST(request: Request) {
|
||||
|
||||
const event = await prisma.event.create({
|
||||
data: {
|
||||
date,
|
||||
date: eventDate,
|
||||
name,
|
||||
description,
|
||||
type: type as EventType,
|
||||
|
||||
Reference in New Issue
Block a user