diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index 46d91302..9be8778e 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -144,13 +144,11 @@ export async function POST(request: Request) { // Validate required fields const requiredFields = { name, - oddScope, niveau, intention, missionType, donneurDOrdre, - projection, - participation + projection }; const missingFields = Object.entries(requiredFields) @@ -180,7 +178,7 @@ export async function POST(request: Request) { const mission = await prisma.mission.create({ data: { name, - oddScope, + oddScope: oddScope || 'default', niveau, intention, missionType, @@ -188,7 +186,7 @@ export async function POST(request: Request) { projection, services: Array.isArray(services) ? services.filter(Boolean) : [], profils: Array.isArray(profils) ? profils.filter(Boolean) : [], - participation, + participation: participation || 'default', creatorId: userId } }); diff --git a/lib/services/n8n-service.ts b/lib/services/n8n-service.ts index fa307688..06cb2f11 100644 --- a/lib/services/n8n-service.ts +++ b/lib/services/n8n-service.ts @@ -18,16 +18,18 @@ export class N8nService { async triggerMissionCreation(data: any): Promise { try { - // Add API key to the data - const dataWithApiKey = { + // Add API key and default values to the data + const dataWithDefaults = { ...data, + oddScope: data.oddScope || 'default', + participation: data.participation || 'default', config: { ...data.config, N8N_API_KEY: this.apiKey } }; - console.log('Triggering n8n workflow with data:', JSON.stringify(dataWithApiKey, null, 2)); + console.log('Triggering n8n workflow with data:', JSON.stringify(dataWithDefaults, null, 2)); console.log('Using webhook URL:', this.webhookUrl); console.log('API key present:', !!this.apiKey); @@ -39,7 +41,7 @@ export class N8nService { 'Content-Type': 'application/json', 'x-api-key': this.apiKey }, - body: dataWithApiKey + body: dataWithDefaults }; console.log('Full request details:', JSON.stringify(requestDetails, null, 2)); @@ -49,7 +51,7 @@ export class N8nService { 'Content-Type': 'application/json', 'x-api-key': this.apiKey }, - body: JSON.stringify(dataWithApiKey), + body: JSON.stringify(dataWithDefaults), }); console.log('Webhook response status:', response.status);