n8n int cleaning

This commit is contained in:
alma 2025-05-12 13:46:27 +02:00
parent 49e486f092
commit b885faa0be
2 changed files with 43 additions and 35 deletions

View File

@ -229,34 +229,46 @@ export async function POST(request: Request) {
fullData: body
});
const workflowResult = await n8nService.triggerMissionCreation({
...body,
missionId: mission.id,
creatorId: mission.creatorId
});
try {
const workflowResult = await n8nService.triggerMissionCreation({
...body,
missionId: mission.id,
creatorId: mission.creatorId
});
console.log('Received workflow result:', workflowResult);
console.log('Received workflow result:', workflowResult);
// Process workflow results
const results = workflowResult.results || {};
console.log('Processing workflow results:', results);
if (!workflowResult.success) {
console.error('N8n workflow failed:', workflowResult.error);
// Continue with mission creation even if n8n workflow fails
return NextResponse.json(mission);
}
// Update mission with integration data
const integrationData = {
leantimeProjectId: results.leantimeProjectId?.toString(),
outlineCollectionId: results.outlineCollectionId?.toString(),
rocketChatChannelId: results.rocketChatChannelId?.toString(),
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString()
} as Prisma.MissionUpdateInput;
// Process workflow results
const results = workflowResult.results || {};
console.log('Processing workflow results:', results);
console.log('Updating mission with integration data:', integrationData);
// Update mission with integration data
const integrationData = {
leantimeProjectId: results.leantimeProjectId?.toString(),
outlineCollectionId: results.outlineCollectionId?.toString(),
rocketChatChannelId: results.rocketChatChannelId?.toString(),
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString()
} as Prisma.MissionUpdateInput;
const updatedMission = await prisma.mission.update({
where: { id: mission.id },
data: integrationData
});
console.log('Updating mission with integration data:', integrationData);
return NextResponse.json(updatedMission);
const updatedMission = await prisma.mission.update({
where: { id: mission.id },
data: integrationData
});
return NextResponse.json(updatedMission);
} catch (error) {
console.error('Error in n8n workflow:', error);
// Return the mission even if n8n workflow fails
return NextResponse.json(mission);
}
} catch (error) {
console.error('Error creating mission:', error);
return NextResponse.json(

View File

@ -413,21 +413,17 @@ export function MissionsAdminPanel() {
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || data.message || 'Failed to create mission');
throw new Error(data.error || 'Failed to create mission');
}
// Check workflow status
if (data.workflow?.status === 'success') {
toast({
title: "Mission créée avec succès",
description: "Tous les gardiens ont été assignés et la mission a été enregistrée.",
});
// Redirect to missions list
router.push('/missions');
} else {
throw new Error(data.workflow?.data?.message || data.error || 'Workflow execution failed');
}
toast({
title: "Mission créée avec succès",
description: "La mission a été créée et les intégrations sont en cours de configuration.",
});
// Redirect to missions list
router.push('/missions');
} catch (error) {
console.error('Error creating mission:', error);
toast({