W n8n attention

This commit is contained in:
alma 2025-05-24 12:29:04 +02:00
parent 2c19339a4c
commit fe4f70cdc9
3 changed files with 8 additions and 9 deletions

View File

@ -217,11 +217,10 @@
{
"parameters": {
"conditions": {
"string": [
"boolean": [
{
"value1": "={{ $json.missionProcessed.services }}",
"operation": "contains",
"value2": "Gite"
"value1": "={{ $json.missionProcessed.services.includes('Gite') || $json.missionProcessed.services.includes('Calcul') }}",
"value2": true
}
]
}
@ -592,7 +591,7 @@
},
{
"parameters": {
"jsCode": "// Defensive access to all nodes\nconst missionData = $node['Process Mission Data']?.json?.missionProcessed || {};\nconst integrationResults = $node['Combine Results']?.json || {};\nconst saveMissionResult = $node['Save Mission To API']?.json || {};\nconst errors = [];\nconst warnings = [];\n\n// Check for actual errors vs expected failures\nif (saveMissionResult.error) {\n errors.push(`Failed to save mission: ${saveMissionResult.error.message || 'Unknown error'}`);\n}\n\n// Track which resources were actually created vs already existed\nconst resourceStatus = {\n gitRepo: false,\n leantimeProject: false,\n docCollection: false,\n rocketChatChannel: false\n};\n\n// Check Git repository\nif (integrationResults.gitRepo?.html_url) {\n resourceStatus.gitRepo = true;\n console.log('Git repository created successfully');\n} else if (integrationResults.gitRepo?.error?.includes('already exists')) {\n console.log('Git repository already exists, this is expected');\n warnings.push('Git repository already exists');\n} else if (integrationResults.gitRepo?.error) {\n errors.push(`Git repository creation failed: ${integrationResults.gitRepo.error}`);\n} else {\n errors.push('Git repository creation failed: Unknown error');\n}\n\n// Check Leantime project\nif (integrationResults.leantimeProject?.result?.[0]) {\n resourceStatus.leantimeProject = true;\n console.log('Leantime project created successfully');\n} else if (integrationResults.leantimeProject?.error?.includes('already exists')) {\n console.log('Leantime project already exists, this is expected');\n warnings.push('Leantime project already exists');\n} else if (integrationResults.leantimeProject?.error) {\n errors.push(`Leantime project creation failed: ${integrationResults.leantimeProject.error}`);\n} else {\n errors.push('Leantime project creation failed: Unknown error');\n}\n\n// Check RocketChat channel\nif (integrationResults.rocketChatChannel?.channel?._id) {\n resourceStatus.rocketChatChannel = true;\n console.log('RocketChat channel created successfully');\n} else if (integrationResults.rocketChatChannel?.error?.includes('error-duplicate-channel-name')) {\n console.log('RocketChat channel already exists, this is expected');\n warnings.push('RocketChat channel already exists');\n} else if (integrationResults.rocketChatChannel?.error) {\n errors.push(`RocketChat channel creation failed: ${integrationResults.rocketChatChannel.error}`);\n} else {\n errors.push('RocketChat channel creation failed: Unknown error');\n}\n\n// Check Documentation collection\nif (integrationResults.docCollection?.data?.id) {\n resourceStatus.docCollection = true;\n console.log('Documentation collection created successfully');\n} else if (integrationResults.docCollection?.error?.includes('already exists')) {\n console.log('Documentation collection already exists, this is expected');\n warnings.push('Documentation collection already exists');\n} else if (integrationResults.docCollection?.error) {\n errors.push(`Documentation collection creation failed: ${integrationResults.docCollection.error}`);\n} else {\n errors.push('Documentation collection creation failed: Unknown error');\n}\n\n// Check if any critical resources failed to create\nconst criticalFailures = errors.filter(error => \n !error.includes('already exists') && \n !error.includes('expected')\n);\n\n// If the mission was successfully saved, consider it a success even if some resources already exist\nconst success = saveMissionResult.body?.message === 'Mission updated successfully' || \n saveMissionResult.body?.message === 'Mission created successfully';\n\n// Determine the final status\nconst status = criticalFailures.length > 0 ? 'error' : \n warnings.length > 0 ? 'warning' : \n 'success';\n\nconst output = {\n success: success && criticalFailures.length === 0,\n status,\n error: errors.length > 0 ? errors.join('; ') : null,\n errors,\n warnings,\n missionData,\n integrationResults,\n saveMissionResult,\n resourceStatus,\n message: status === 'success' ? \n 'Mission integration complete: All systems updated successfully' : \n status === 'warning' ? \n `Mission integration complete with warnings: ${warnings.join('; ')}` : \n `Mission integration failed: ${errors.join('; ')}`\n};\n\n// Log the final status\nconsole.log('Process Results - Final Status:', {\n success: output.success,\n status: output.status,\n errors: output.errors.length,\n warnings: output.warnings.length,\n resourceStatus\n});\n\nreturn output;"
"jsCode": "// Defensive access to all nodes\nconst missionData = $node['Process Mission Data']?.json?.missionProcessed || {};\nconst integrationResults = $node['Combine Results']?.json || {};\nconst saveMissionResult = $node['Save Mission To API']?.json || {};\nconst errors = [];\nconst warnings = [];\n\n// Check for actual errors vs expected failures\nif (saveMissionResult.error) {\n errors.push(`Failed to save mission: ${saveMissionResult.error.message || 'Unknown error'}`);\n}\n\n// Track which resources were actually created vs already existed\nconst resourceStatus = {\n gitRepo: false,\n leantimeProject: false,\n docCollection: false,\n rocketChatChannel: false\n};\n\n// Check if Git repository is needed\nconst needsGitRepo = Array.isArray(missionData.services) && \n (missionData.services.includes('Gite') || missionData.services.includes('Calcul'));\n\n// Process Git repository result only if needed\nif (needsGitRepo) {\n if (integrationResults.gitRepo?.html_url) {\n resourceStatus.gitRepo = true;\n console.log('Git repository created successfully');\n } else if (integrationResults.gitRepo?.error?.includes('already exists')) {\n console.log('Git repository already exists, this is expected');\n warnings.push('Git repository already exists');\n } else if (integrationResults.gitRepo?.error) {\n errors.push(`Git repository creation failed: ${integrationResults.gitRepo.error}`);\n } else {\n errors.push('Git repository creation failed: Unknown error');\n }\n} else {\n console.log('Git repository not needed for this mission');\n resourceStatus.gitRepo = true; // Mark as successful since it's not needed\n}\n\n// Process Leantime project result\nif (integrationResults.leantimeProject?.error?.includes('already exists')) {\n console.log('Leantime project already exists');\n integrationResults.leantimeProject = { exists: true };\n} else if (integrationResults.leantimeProject?.result?.[0]) {\n resourceStatus.leantimeProject = true;\n console.log('Leantime project created successfully with ID:', integrationResults.leantimeProject.result[0]);\n} else if (integrationResults.leantimeProject?.error) {\n errors.push(`Leantime project creation failed: ${integrationResults.leantimeProject.error}`);\n}\n\n// Process Documentation collection result\nif (integrationResults.docCollection?.error?.includes('already exists')) {\n console.log('Documentation collection already exists');\n integrationResults.docCollection = { exists: true };\n} else if (integrationResults.docCollection?.data?.id) {\n resourceStatus.docCollection = true;\n console.log('Documentation collection created successfully with ID:', integrationResults.docCollection.data.id);\n} else if (integrationResults.docCollection?.error) {\n errors.push(`Documentation collection creation failed: ${integrationResults.docCollection.error}`);\n}\n\n// Process RocketChat channel result\nif (integrationResults.rocketChatChannel?.error?.includes('error-duplicate-channel-name')) {\n console.log('RocketChat channel already exists');\n integrationResults.rocketChatChannel = { exists: true };\n} else if (integrationResults.rocketChatChannel?.channel?._id) {\n resourceStatus.rocketChatChannel = true;\n console.log('RocketChat channel created successfully');\n} else if (integrationResults.rocketChatChannel?.error) {\n errors.push(`RocketChat channel creation failed: ${integrationResults.rocketChatChannel.error}`);\n}\n\n// Check if any critical resources failed to create\nconst criticalFailures = errors.filter(error => \n !error.includes('already exists') && \n !error.includes('expected')\n);\n\n// If the mission was successfully saved, consider it a success even if some resources already exist\nconst success = saveMissionResult.body?.message === 'Mission updated successfully' || \n saveMissionResult.body?.message === 'Mission created successfully';\n\n// Determine the final status\nconst status = criticalFailures.length > 0 ? 'error' : \n warnings.length > 0 ? 'warning' : \n 'success';\n\nconst output = {\n success: success && criticalFailures.length === 0,\n status,\n error: errors.length > 0 ? errors.join('; ') : null,\n errors,\n warnings,\n missionData,\n integrationResults,\n saveMissionResult,\n resourceStatus,\n message: status === 'success' ? \n 'Mission integration complete: All systems updated successfully' : \n status === 'warning' ? \n `Mission integration complete with warnings: ${warnings.join('; ')}` : \n `Mission integration failed: ${errors.join('; ')}`\n};\n\n// Log the final status\nconsole.log('Process Results - Final Status:', {\n success: output.success,\n status: output.status,\n errors: output.errors.length,\n warnings: output.warnings.length,\n resourceStatus,\n needsGitRepo\n});\n\nreturn output;"
},
"name": "Process Results",
"type": "n8n-nodes-base.code",

View File

@ -83,11 +83,11 @@ export async function GET(request: Request, props: { params: Promise<{ missionId
// Add public URLs to mission logo and attachments
const missionWithUrls = {
...mission,
logoUrl: mission.logo ? `/api/missions/image/${mission.logo}` : null,
logoUrl: mission.logo ? `/api/missions/image/${mission.logo.replace('missions/', '')}` : null,
logo: mission.logo,
attachments: mission.attachments.map((attachment: { id: string; filename: string; filePath: string; fileType: string; fileSize: number; createdAt: Date }) => ({
...attachment,
publicUrl: `/api/missions/image/${attachment.filePath}`
publicUrl: `/api/missions/image/${attachment.filePath.replace('missions/', '')}`
}))
};

View File

@ -151,11 +151,11 @@ export async function GET(request: Request) {
// Transform missions to include public URLs
const missionsWithUrls = missions.map(mission => ({
...mission,
logoUrl: mission.logo ? `/api/missions/image/${mission.logo}` : null,
logoUrl: mission.logo ? `/api/missions/image/${mission.logo.replace('missions/', '')}` : null,
logo: mission.logo,
attachments: mission.attachments?.map(attachment => ({
...attachment,
publicUrl: `/api/missions/image/${attachment.filePath}`
publicUrl: `/api/missions/image/${attachment.filePath.replace('missions/', '')}`
})) || []
}));