n8n int cleaning

This commit is contained in:
alma 2025-05-18 08:57:06 +02:00
parent 2d25992870
commit f4cdad3589
2 changed files with 17 additions and 12 deletions

View File

@ -152,11 +152,12 @@ export async function POST(request: Request) {
try { try {
const session = await getServerSession(authOptions); const session = await getServerSession(authOptions);
if (!session?.user) { if (!session?.user) {
console.error('Unauthorized access attempt - no session or user');
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
const body = await request.json(); const body = await request.json();
console.log('Received mission creation request:', body); console.log('Received mission creation request:', JSON.stringify(body, null, 2));
const { name, oddScope, niveau, intention, missionType, donneurDOrdre, projection, services, participation, profils, guardians, volunteers } = body; const { name, oddScope, niveau, intention, missionType, donneurDOrdre, projection, services, participation, profils, guardians, volunteers } = body;
@ -194,6 +195,7 @@ export async function POST(request: Request) {
return NextResponse.json({ error: 'A mission with this name already exists' }, { status: 400 }); return NextResponse.json({ error: 'A mission with this name already exists' }, { status: 400 });
} }
console.log('Creating mission in database...');
// Create the mission // Create the mission
const mission = await prisma.mission.create({ const mission = await prisma.mission.create({
data: { data: {
@ -204,17 +206,18 @@ export async function POST(request: Request) {
missionType, missionType,
donneurDOrdre, donneurDOrdre,
projection, projection,
services, services: Array.isArray(services) ? services.filter(Boolean) : [],
profils, profils: Array.isArray(profils) ? profils.filter(Boolean) : [],
participation, participation,
creatorId: session.user.id creatorId: session.user.id
} }
}); });
console.log('Created mission:', mission); console.log('Created mission:', JSON.stringify(mission, null, 2));
// Add guardians and volunteers // Add guardians and volunteers
if (guardians || volunteers) { if (guardians || volunteers) {
console.log('Adding guardians and volunteers...');
const missionUsers: MissionUserInput[] = []; const missionUsers: MissionUserInput[] = [];
// Add guardians // Add guardians
@ -244,6 +247,7 @@ export async function POST(request: Request) {
} }
if (missionUsers.length > 0) { if (missionUsers.length > 0) {
console.log('Creating mission users:', JSON.stringify(missionUsers, null, 2));
await prisma.missionUser.createMany({ await prisma.missionUser.createMany({
data: missionUsers data: missionUsers
}); });
@ -252,12 +256,12 @@ export async function POST(request: Request) {
// Trigger n8n workflow // Trigger n8n workflow
const n8nService = new N8nService(); const n8nService = new N8nService();
console.log('About to trigger n8n workflow with data:', { console.log('About to trigger n8n workflow with data:', JSON.stringify({
missionId: mission.id, missionId: mission.id,
name: mission.name, name: mission.name,
creatorId: mission.creatorId, creatorId: mission.creatorId,
fullData: body fullData: body
}); }, null, 2));
try { try {
const workflowResult = await n8nService.triggerMissionCreation({ const workflowResult = await n8nService.triggerMissionCreation({
@ -266,7 +270,7 @@ export async function POST(request: Request) {
creatorId: mission.creatorId creatorId: mission.creatorId
}); });
console.log('Received workflow result:', workflowResult); console.log('Received workflow result:', JSON.stringify(workflowResult, null, 2));
if (!workflowResult.success) { if (!workflowResult.success) {
console.error('N8n workflow failed:', workflowResult.error); console.error('N8n workflow failed:', workflowResult.error);
@ -276,7 +280,7 @@ export async function POST(request: Request) {
// Process workflow results // Process workflow results
const results = workflowResult.results || {}; const results = workflowResult.results || {};
console.log('Processing workflow results:', results); console.log('Processing workflow results:', JSON.stringify(results, null, 2));
// Update mission with integration data // Update mission with integration data
const integrationData = { const integrationData = {
@ -286,7 +290,7 @@ export async function POST(request: Request) {
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString() giteaRepositoryUrl: results.giteaRepositoryUrl?.toString()
} as Prisma.MissionUpdateInput; } as Prisma.MissionUpdateInput;
console.log('Updating mission with integration data:', integrationData); console.log('Updating mission with integration data:', JSON.stringify(integrationData, null, 2));
const updatedMission = await prisma.mission.update({ const updatedMission = await prisma.mission.update({
where: { id: mission.id }, where: { id: mission.id },

View File

@ -379,7 +379,7 @@ export function MissionsAdminPanel() {
// Handle mission submission // Handle mission submission
const handleSubmitMission = async () => { const handleSubmitMission = async () => {
console.log('Starting mission submission...'); console.log('Starting mission submission...');
console.log('Current mission data:', missionData); console.log('Current mission data:', JSON.stringify(missionData, null, 2));
console.log('Guardians:', { console.log('Guardians:', {
gardienDuTemps, gardienDuTemps,
gardienDeLaParole, gardienDeLaParole,
@ -408,7 +408,7 @@ export function MissionsAdminPanel() {
volunteers: volontaires volunteers: volontaires
}; };
console.log('Submitting mission data:', formattedData); console.log('Submitting mission data:', JSON.stringify(formattedData, null, 2));
const response = await fetch('/api/missions', { const response = await fetch('/api/missions', {
method: 'POST', method: 'POST',
@ -420,9 +420,10 @@ export function MissionsAdminPanel() {
console.log('Response status:', response.status); console.log('Response status:', response.status);
const data = await response.json(); const data = await response.json();
console.log('Response data:', data); console.log('Response data:', JSON.stringify(data, null, 2));
if (!response.ok) { if (!response.ok) {
console.error('Error response:', data);
throw new Error(data.error || 'Failed to create mission'); throw new Error(data.error || 'Failed to create mission');
} }