From 10a970ee62700e650e57cd272e033a00eb2f384e Mon Sep 17 00:00:00 2001 From: alma Date: Tue, 6 May 2025 20:00:06 +0200 Subject: [PATCH] missions api2 gitea --- app/api/missions/[missionId]/route.ts | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app/api/missions/[missionId]/route.ts b/app/api/missions/[missionId]/route.ts index 1e72168d..6d0cb256 100644 --- a/app/api/missions/[missionId]/route.ts +++ b/app/api/missions/[missionId]/route.ts @@ -4,6 +4,7 @@ import { authOptions } from "@/app/api/auth/options"; import { prisma } from '@/lib/prisma'; import { deleteMissionLogo } from '@/lib/mission-uploads'; import { getPublicUrl, S3_CONFIG } from '@/lib/s3'; +import { IntegrationService } from '@/lib/services/integration-service'; // Helper function to check authentication async function checkAuth(request: Request) { @@ -281,6 +282,38 @@ export async function DELETE(request: Request, props: { params: Promise<{ missio return NextResponse.json({ error: 'Mission not found or not authorized to delete' }, { status: 404 }); } + // Initialize integration service to clean up external resources + const integrationService = new IntegrationService(); + + // Extract integration IDs + const leantimeProjectId = mission.leantimeProjectId ? parseInt(mission.leantimeProjectId) : undefined; + const outlineCollectionId = mission.outlineCollectionId || undefined; + const rocketChatChannelId = mission.rocketChatChannelId || undefined; + const giteaRepositoryUrl = mission.giteaRepositoryUrl || undefined; + + // Log the external resources being cleaned up + console.log('Cleaning up external resources for mission:', { + missionId, + leantimeProjectId, + outlineCollectionId, + rocketChatChannelId, + giteaRepositoryUrl + }); + + try { + // Perform rollback of all external integrations + await integrationService.rollbackIntegrations( + leantimeProjectId, + outlineCollectionId, + rocketChatChannelId, + giteaRepositoryUrl + ); + console.log('Successfully cleaned up external resources for mission:', missionId); + } catch (integrationError) { + console.error('Error cleaning up external integrations:', integrationError); + // Continue with mission deletion even if integration cleanup fails + } + // Delete logo if exists if (mission.logo) { try {