missions finition
This commit is contained in:
parent
680abdbc54
commit
d743f4f980
@ -40,7 +40,7 @@ export async function GET(
|
|||||||
const { missionId } = await params;
|
const { missionId } = await params;
|
||||||
const userId = session.user.id;
|
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({
|
const mission = await prisma.mission.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: missionId,
|
id: missionId,
|
||||||
@ -49,11 +49,7 @@ export async function GET(
|
|||||||
{ missionUsers: { some: { userId } } }
|
{ missionUsers: { some: { userId } } }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
select: {
|
include: {
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
creatorId: true,
|
|
||||||
isClosed: true,
|
|
||||||
creator: {
|
creator: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@ -61,10 +57,7 @@ export async function GET(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
missionUsers: {
|
missionUsers: {
|
||||||
select: {
|
include: {
|
||||||
id: true,
|
|
||||||
role: true,
|
|
||||||
userId: true,
|
|
||||||
user: {
|
user: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
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({ 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) {
|
} catch (error: any) {
|
||||||
console.error('Error fetching mission:', error);
|
console.error('Error fetching mission:', error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user