n8n int cleaning
This commit is contained in:
parent
49e486f092
commit
b885faa0be
@ -229,34 +229,46 @@ export async function POST(request: Request) {
|
|||||||
fullData: body
|
fullData: body
|
||||||
});
|
});
|
||||||
|
|
||||||
const workflowResult = await n8nService.triggerMissionCreation({
|
try {
|
||||||
...body,
|
const workflowResult = await n8nService.triggerMissionCreation({
|
||||||
missionId: mission.id,
|
...body,
|
||||||
creatorId: mission.creatorId
|
missionId: mission.id,
|
||||||
});
|
creatorId: mission.creatorId
|
||||||
|
});
|
||||||
|
|
||||||
console.log('Received workflow result:', workflowResult);
|
console.log('Received workflow result:', workflowResult);
|
||||||
|
|
||||||
// Process workflow results
|
if (!workflowResult.success) {
|
||||||
const results = workflowResult.results || {};
|
console.error('N8n workflow failed:', workflowResult.error);
|
||||||
console.log('Processing workflow results:', results);
|
// Continue with mission creation even if n8n workflow fails
|
||||||
|
return NextResponse.json(mission);
|
||||||
|
}
|
||||||
|
|
||||||
// Update mission with integration data
|
// Process workflow results
|
||||||
const integrationData = {
|
const results = workflowResult.results || {};
|
||||||
leantimeProjectId: results.leantimeProjectId?.toString(),
|
console.log('Processing workflow results:', results);
|
||||||
outlineCollectionId: results.outlineCollectionId?.toString(),
|
|
||||||
rocketChatChannelId: results.rocketChatChannelId?.toString(),
|
|
||||||
giteaRepositoryUrl: results.giteaRepositoryUrl?.toString()
|
|
||||||
} as Prisma.MissionUpdateInput;
|
|
||||||
|
|
||||||
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({
|
console.log('Updating mission with integration data:', integrationData);
|
||||||
where: { id: mission.id },
|
|
||||||
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) {
|
} catch (error) {
|
||||||
console.error('Error creating mission:', error);
|
console.error('Error creating mission:', error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@ -413,21 +413,17 @@ export function MissionsAdminPanel() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (!response.ok) {
|
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
|
toast({
|
||||||
if (data.workflow?.status === 'success') {
|
title: "Mission créée avec succès",
|
||||||
toast({
|
description: "La mission a été créée et les intégrations sont en cours de configuration.",
|
||||||
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');
|
||||||
|
|
||||||
// Redirect to missions list
|
|
||||||
router.push('/missions');
|
|
||||||
} else {
|
|
||||||
throw new Error(data.workflow?.data?.message || data.error || 'Workflow execution failed');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error creating mission:', error);
|
console.error('Error creating mission:', error);
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user