updates
This commit is contained in:
97
server/api/eoi/delete-document.ts
Normal file
97
server/api/eoi/delete-document.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { getMinioClient } from '~/server/utils/minio';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const xTagHeader = getRequestHeader(event, "x-tag");
|
||||
|
||||
console.log('[EOI Delete] Request received with x-tag:', xTagHeader);
|
||||
|
||||
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
|
||||
console.error('[EOI Delete] Authentication failed - invalid x-tag');
|
||||
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
|
||||
}
|
||||
|
||||
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 $fetch(`/api/get-interest-by-id`, {
|
||||
headers: {
|
||||
'x-tag': xTagHeader,
|
||||
},
|
||||
params: {
|
||||
id: interestId,
|
||||
},
|
||||
});
|
||||
|
||||
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',
|
||||
'EOI Document': null,
|
||||
'EOI Time Sent': null,
|
||||
'Signature Link Client': null,
|
||||
'Signature Link CC': null,
|
||||
'Signature Link Developer': null,
|
||||
'Documeso ID': null,
|
||||
'reminder_enabled': false
|
||||
};
|
||||
|
||||
console.log('[EOI Delete] Resetting interest fields');
|
||||
|
||||
// Update the interest
|
||||
await $fetch('/api/update-interest', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-tag': xTagHeader,
|
||||
},
|
||||
body: {
|
||||
id: interestId,
|
||||
data: updateData
|
||||
}
|
||||
});
|
||||
|
||||
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',
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -109,18 +109,13 @@ export default defineEventHandler(async (event) => {
|
||||
console.log('[EOI Upload] Updating interest with EOI document info');
|
||||
await updateInterestEOIDocument(interestId, documentData);
|
||||
|
||||
// Also update the status fields
|
||||
// Update the status fields for uploaded (signed) EOI
|
||||
const updateData: any = {
|
||||
'EOI Status': 'Waiting for Signatures',
|
||||
'EOI Time Sent': new Date().toISOString()
|
||||
'EOI Status': 'Signed',
|
||||
'EOI Time Sent': new Date().toISOString(),
|
||||
'Sales Process Level': 'Signed LOI and NDA'
|
||||
};
|
||||
console.log('[EOI Upload] Updating interest status fields');
|
||||
|
||||
// Update Sales Process Level if it's below "LOI and NDA Sent"
|
||||
const currentLevel = await getCurrentSalesLevel(interestId);
|
||||
if (shouldUpdateSalesLevel(currentLevel)) {
|
||||
updateData['Sales Process Level'] = 'LOI and NDA Sent';
|
||||
}
|
||||
console.log('[EOI Upload] Updating interest status fields for signed EOI');
|
||||
|
||||
// Update the interest
|
||||
await $fetch('/api/update-interest', {
|
||||
|
||||
Reference in New Issue
Block a user