n8n
This commit is contained in:
parent
b885faa0be
commit
3d0ad07582
@ -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 }
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user