From 67d79233ade5817b24489da8f835bbe4d4e00296 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 24 May 2025 20:51:25 +0200 Subject: [PATCH] W n8n attention vm --- app/api/missions/route.ts | 41 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index d13dc75c..9632b764 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -247,7 +247,42 @@ export async function POST(request: Request) { console.log('Mission created successfully:', JSON.stringify(mission, null, 2)); - // Step 2: Upload logo to Minio if present + // Step 2: Create mission users (guardians and volunteers) + const missionUsers = []; + + // Add guardians + if (body.guardians) { + for (const [role, guardianId] of Object.entries(body.guardians)) { + if (guardianId) { + missionUsers.push({ + missionId: mission.id, + userId: guardianId, + role: role + }); + } + } + } + + // Add volunteers + if (body.volunteers && body.volunteers.length > 0) { + for (const volunteerId of body.volunteers) { + missionUsers.push({ + missionId: mission.id, + userId: volunteerId, + role: 'volontaire' + }); + } + } + + // Create all mission users + if (missionUsers.length > 0) { + await prisma.missionUser.createMany({ + data: missionUsers + }); + console.log('Mission users created:', missionUsers); + } + + // Step 3: Upload logo to Minio if present let logoPath = null; if (body.logo?.data) { try { @@ -274,7 +309,7 @@ export async function POST(request: Request) { } } - // Step 3: Handle attachments if present + // Step 4: Handle attachments if present if (body.attachments && body.attachments.length > 0) { try { const attachmentPromises = body.attachments.map(async (attachment: any) => { @@ -307,7 +342,7 @@ export async function POST(request: Request) { } } - // Step 4: Verify all files are in Minio before triggering n8n + // Step 5: Verify all files are in Minio before triggering n8n try { // Verify logo if present if (logoPath) {