port-nimara-client-portal/server/api/eoi/delete-document.ts

82 lines
2.6 KiB
TypeScript
Raw Normal View History

import { requireAuth } from '~/server/utils/auth';
2025-06-10 15:52:30 +02:00
import { getMinioClient } from '~/server/utils/minio';
import { getInterestById, updateInterest } from '~/server/utils/nocodb';
2025-06-10 15:52:30 +02:00
export default defineEventHandler(async (event) => {
// Check authentication (x-tag header OR Keycloak session)
await requireAuth(event);
2025-06-10 15:52:30 +02:00
console.log('[EOI Delete] Request received');
2025-06-10 15:52:30 +02:00
try {
const body = await readBody(event);
const { interestId } = body;
console.log('[EOI Delete] Interest ID:', interestId);
if (!interestId) {
console.error('[EOI Delete] No interest ID provided');
throw createError({
statusCode: 400,
statusMessage: 'Interest ID is required',
});
}
// Get current interest data to find EOI documents
const interest = await getInterestById(interestId);
2025-06-10 15:52:30 +02:00
const eoiDocuments = interest['EOI Document'] || [];
console.log('[EOI Delete] Found EOI documents:', eoiDocuments);
// Delete all EOI documents from MinIO
const client = getMinioClient();
for (const doc of eoiDocuments) {
const filename = (doc as any).filename;
if (filename) {
try {
console.log('[EOI Delete] Deleting file from MinIO:', filename);
await client.removeObject('client-portal', filename);
console.log('[EOI Delete] Successfully deleted:', filename);
} catch (error: any) {
console.error('[EOI Delete] Failed to delete file:', filename, error);
// Continue with other files even if one fails
}
}
}
// Reset interest fields
const updateData = {
'EOI Status': 'Awaiting Further Details',
'Sales Process Level': 'Specific Qualified Interest',
fix: Comprehensive EOI cleanup and mobile UI improvements Database Cleanup Enhancements: - Fixed missing embedded signature link cleanup in deletion endpoints - Both delete-generated-document and delete-document now properly clear: * EmbeddedSignatureLinkClient, EmbeddedSignatureLinkCC, EmbeddedSignatureLinkDeveloper * All legacy signature links and documensoID references - Enhanced validation endpoint to detect and clean orphaned records automatically EOI Section Reactivity Fixes: - Added local reactive state (documentValidated, documentExists) for immediate UI updates - EOI section now instantly shows Generate UI when documents are deleted/invalid - No more phantom signatory status displays after document deletion - Improved hasGeneratedEOI computed property with validation state override Mobile UI Improvements: - Implemented stacked badge layout for interest table on mobile - Contact info + status badges now stack vertically (60% width) - Eliminated horizontal scrolling issues on mobile devices - Enhanced email thread view with proper width constraints and text wrapping - Made email refresh button round with better mobile styling Technical Enhancements: - Comprehensive field cleanup using undefined instead of null for proper database reset - Enhanced error handling for document validation and deletion - Improved logging for debugging EOI state transitions - Better handling of edge cases where documensoID exists but document was deleted externally All EOI-related operations now properly maintain database consistency and provide immediate visual feedback to users.
2025-06-12 17:27:10 +02:00
'EOI Document': undefined,
'EOI Time Sent': undefined,
'Signature Link Client': undefined,
'Signature Link CC': undefined,
'Signature Link Developer': undefined,
'EmbeddedSignatureLinkClient': undefined,
'EmbeddedSignatureLinkCC': undefined,
'EmbeddedSignatureLinkDeveloper': undefined,
'documensoID': undefined
2025-06-10 15:52:30 +02:00
};
console.log('[EOI Delete] Resetting interest fields');
// Update the interest
await updateInterest(interestId, updateData as any);
2025-06-10 15:52:30 +02:00
console.log('[EOI Delete] Delete completed successfully');
return {
success: true,
message: 'EOI document deleted successfully',
};
} catch (error: any) {
console.error('[EOI Delete] Failed to delete EOI document:', error);
console.error('[EOI Delete] Error stack:', error.stack);
throw createError({
statusCode: 500,
statusMessage: error.message || 'Failed to delete EOI document',
});
}
});