From 3d0ad07582bf59ab24b7c266159704b854f5516b Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 12 May 2025 13:47:34 +0200 Subject: [PATCH] n8n --- app/api/missions/route.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index f7d9ca88..848bc3e2 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -156,8 +156,34 @@ export async function POST(request: Request) { } const body = await request.json(); + console.log('Received mission creation request:', body); + const { name, oddScope, niveau, intention, missionType, donneurDOrdre, projection, services, participation, profils, guardians, volunteers } = body; + // Validate required fields + const requiredFields = { + name, + oddScope, + niveau, + intention, + missionType, + donneurDOrdre, + projection, + participation + }; + + const missingFields = Object.entries(requiredFields) + .filter(([_, value]) => !value) + .map(([key]) => key); + + if (missingFields.length > 0) { + console.error('Missing required fields:', missingFields); + return NextResponse.json({ + error: 'Missing required fields', + missingFields + }, { status: 400 }); + } + // Check if mission with same name exists const existingMission = await prisma.mission.findFirst({ where: { name } @@ -183,6 +209,8 @@ export async function POST(request: Request) { } }); + console.log('Created mission:', mission); + // Add guardians and volunteers if (guardians || volunteers) { const missionUsers: MissionUserInput[] = []; @@ -272,7 +300,7 @@ export async function POST(request: Request) { } catch (error) { console.error('Error creating mission:', error); return NextResponse.json( - { error: 'Failed to create mission' }, + { error: 'Failed to create mission', details: error instanceof Error ? error.message : String(error) }, { status: 500 } ); }