missions finition

This commit is contained in:
alma 2026-01-21 14:03:15 +01:00
parent d743f4f980
commit bd112deec5
2 changed files with 50 additions and 3 deletions

View File

@ -35,7 +35,8 @@ export async function POST(
include: { include: {
user: true user: true
} }
} },
calendars: true
} }
}); });
@ -89,9 +90,32 @@ export async function POST(
logger.debug('Calling N8N NeahMissionClose webhook', { logger.debug('Calling N8N NeahMissionClose webhook', {
missionId: mission.id, missionId: mission.id,
missionName: mission.name, missionName: mission.name,
hasRepoName: !!repoName hasRepoName: !!repoName,
calendarsCount: mission.calendars.length
}); });
// Delete all calendars associated with this mission before closing
try {
if (mission.calendars.length > 0) {
const calendarIds = mission.calendars.map(cal => cal.id);
await prisma.calendar.deleteMany({
where: {
id: { in: calendarIds }
}
});
logger.debug('Mission calendars deleted before closing', {
missionId,
calendarsDeleted: mission.calendars.length
});
}
} catch (calendarDeleteError) {
logger.error('Error deleting mission calendars before closing (continuing)', {
error: calendarDeleteError instanceof Error ? calendarDeleteError.message : String(calendarDeleteError),
missionId
});
// Continue with closing even if calendar deletion fails
}
// Call N8N webhook // Call N8N webhook
const webhookUrl = process.env.N8N_CLOSE_MISSION_WEBHOOK_URL || 'https://brain.slm-lab.net/webhook/NeahMissionClose'; const webhookUrl = process.env.N8N_CLOSE_MISSION_WEBHOOK_URL || 'https://brain.slm-lab.net/webhook/NeahMissionClose';
const apiKey = process.env.N8N_API_KEY || ''; const apiKey = process.env.N8N_API_KEY || '';

View File

@ -141,9 +141,32 @@ export async function DELETE(
missionId, missionId,
missionName: mission.name, missionName: mission.name,
hasLogo: !!mission.logo, hasLogo: !!mission.logo,
attachmentsCount: mission.attachments.length attachmentsCount: mission.attachments.length,
calendarsCount: mission.calendars.length
}); });
// Step 0: Delete all calendars associated with this mission
try {
if (mission.calendars.length > 0) {
const calendarIds = mission.calendars.map(cal => cal.id);
await prisma.calendar.deleteMany({
where: {
id: { in: calendarIds }
}
});
logger.debug('Mission calendars deleted', {
missionId,
calendarsDeleted: mission.calendars.length
});
}
} catch (calendarDeleteError) {
logger.error('Error deleting mission calendars (continuing)', {
error: calendarDeleteError instanceof Error ? calendarDeleteError.message : String(calendarDeleteError),
missionId
});
// Continue with deletion even if calendar deletion fails
}
// Step 1: Delete all files from S3/MinIO // Step 1: Delete all files from S3/MinIO
try { try {
// Delete logo if exists // Delete logo if exists