From 70a921b0f56bba6ce8d7762eb21bc7398a88b1d2 Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 5 May 2025 12:53:28 +0200 Subject: [PATCH] build fix --- app/api/announcements/[id]/route.ts | 8 ++++---- app/api/calendars/[id]/route.ts | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/api/announcements/[id]/route.ts b/app/api/announcements/[id]/route.ts index befe9145..4f4edcb6 100644 --- a/app/api/announcements/[id]/route.ts +++ b/app/api/announcements/[id]/route.ts @@ -22,7 +22,7 @@ async function userExists(userId: string): Promise { // GET - Retrieve a specific announcement export async function GET( req: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { try { const session = await getServerSession(authOptions); @@ -31,7 +31,7 @@ export async function GET( return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - const { id } = params; + const { id } = await params; // Find announcement by ID const announcement = await prisma.announcement.findUnique({ @@ -76,7 +76,7 @@ export async function GET( // DELETE - Remove an announcement export async function DELETE( req: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { try { const session = await getServerSession(authOptions); @@ -107,7 +107,7 @@ export async function DELETE( return NextResponse.json({ error: "Forbidden" }, { status: 403 }); } - const { id } = params; + const { id } = await params; // Check if announcement exists const announcement = await prisma.announcement.findUnique({ diff --git a/app/api/calendars/[id]/route.ts b/app/api/calendars/[id]/route.ts index 25ea758f..c6ce4151 100644 --- a/app/api/calendars/[id]/route.ts +++ b/app/api/calendars/[id]/route.ts @@ -19,7 +19,7 @@ import { prisma } from "@/lib/prisma"; */ export async function GET( req: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { const session = await getServerSession(authOptions); @@ -28,9 +28,11 @@ export async function GET( } try { + const { id } = await params; + const calendar = await prisma.calendar.findUnique({ where: { - id: params.id, + id: id, }, }); @@ -69,7 +71,7 @@ export async function GET( */ export async function PUT( req: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { const session = await getServerSession(authOptions); @@ -78,10 +80,12 @@ export async function PUT( } try { + const { id } = await params; + // Vérifier que le calendrier existe et appartient à l'utilisateur const existingCalendar = await prisma.calendar.findUnique({ where: { - id: params.id, + id: id, }, }); @@ -108,7 +112,7 @@ export async function PUT( const updatedCalendar = await prisma.calendar.update({ where: { - id: params.id, + id: id, }, data: { name, @@ -140,7 +144,7 @@ export async function PUT( */ export async function DELETE( req: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { const session = await getServerSession(authOptions); @@ -149,10 +153,12 @@ export async function DELETE( } try { + const { id } = await params; + // Verify calendar ownership const calendar = await prisma.calendar.findFirst({ where: { - id: params.id, + id: id, userId: session.user.id, }, }); @@ -167,7 +173,7 @@ export async function DELETE( // Delete the calendar (this will also delete all associated events due to the cascade delete) await prisma.calendar.delete({ where: { - id: params.id, + id: id, }, });