From 5fd673cdfb22dcc343702fa7d83f36ca21fa4afd Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 23 May 2025 10:33:31 +0200 Subject: [PATCH] W n8n --- app/api/missions/route.ts | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index b58fc0b5..ea0e55dd 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -205,30 +205,29 @@ export async function POST(request: Request) { // Prepare the data for n8n const n8nData = { - ...body, + name: body.name, + oddScope: Array.isArray(body.oddScope) ? body.oddScope : [body.oddScope], + niveau: body.niveau || 'default', + intention: body.intention?.trim() || '', + missionType: body.missionType || 'default', + donneurDOrdre: body.donneurDOrdre || 'default', + projection: body.projection || 'default', + services: Array.isArray(body.services) ? body.services : [], + participation: body.participation || 'default', + profils: Array.isArray(body.profils) ? body.profils : [], + guardians: body.guardians || {}, + volunteers: Array.isArray(body.volunteers) ? body.volunteers : [], creatorId: userId, - 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'] + config: { + N8N_API_KEY: process.env.N8N_API_KEY, + MISSION_API_URL: process.env.NEXT_PUBLIC_API_URL || 'https://api.slm-lab.net/api' } }; try { console.log('Sending data to n8n workflow:', { ...n8nData, - password: undefined // Don't log sensitive data + config: { ...n8nData.config, N8N_API_KEY: '[REDACTED]' } // Don't log sensitive data }); const workflowResult = await n8nService.triggerMissionCreation(n8nData);