From d743f4f9809359ecf5cc13a9837a04403618ad01 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 21 Jan 2026 13:27:24 +0100 Subject: [PATCH] missions finition --- app/api/missions/[missionId]/route.ts | 36 +++++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/api/missions/[missionId]/route.ts b/app/api/missions/[missionId]/route.ts index 55d0fe5..e4533a1 100644 --- a/app/api/missions/[missionId]/route.ts +++ b/app/api/missions/[missionId]/route.ts @@ -40,7 +40,7 @@ export async function GET( const { missionId } = await params; const userId = session.user.id; - // Find mission and check access + // Find mission and check access - return all fields like the list endpoint const mission = await prisma.mission.findFirst({ where: { id: missionId, @@ -49,11 +49,7 @@ export async function GET( { missionUsers: { some: { userId } } } ] }, - select: { - id: true, - name: true, - creatorId: true, - isClosed: true, + include: { creator: { select: { id: true, @@ -61,10 +57,7 @@ export async function GET( } }, missionUsers: { - select: { - id: true, - role: true, - userId: true, + include: { user: { select: { id: true, @@ -72,6 +65,17 @@ export async function GET( } } } + }, + attachments: { + select: { + id: true, + filename: true, + filePath: true, + fileType: true, + fileSize: true, + createdAt: true + }, + orderBy: { createdAt: 'desc' } } } }); @@ -80,7 +84,17 @@ export async function GET( return NextResponse.json({ error: 'Mission not found or access denied' }, { status: 404 }); } - return NextResponse.json(mission); + // Transform mission to include public URLs (same as list endpoint) + const missionWithUrls = { + ...mission, + logoUrl: mission.logo ? `/api/missions/image/${mission.logo}` : null, + attachments: mission.attachments?.map(attachment => ({ + ...attachment, + publicUrl: `/api/missions/image/${attachment.filePath}` + })) || [] + }; + + return NextResponse.json(missionWithUrls); } catch (error: any) { console.error('Error fetching mission:', error); return NextResponse.json(