diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index 84b74069..b58fc0b5 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -202,10 +202,27 @@ export async function POST(request: Request) { if (!isN8nRequest) { // Trigger n8n workflow const n8nService = new N8nService(); + + // Prepare the data for n8n const n8nData = { ...body, creatorId: userId, - requestId + requestId, + // Ensure guardians and volunteers are properly formatted + guardians: body.guardians ? Object.entries(body.guardians).reduce((acc, [role, userId]) => { + if (userId) { + acc[role] = userId; + } + return acc; + }, {} as Record) : {}, + volunteers: Array.isArray(body.volunteers) ? body.volunteers.filter(Boolean) : [], + // Add metadata for n8n workflow + metadata: { + hasGuardians: Boolean(body.guardians && Object.keys(body.guardians).length > 0), + volunteersCount: Array.isArray(body.volunteers) ? body.volunteers.length : 0, + hasConfig: true, + configKeys: ['N8N_API_KEY', 'MISSION_API_URL'] + } }; try {