This commit is contained in:
2025-06-10 16:48:40 +02:00
parent 49aa47ab10
commit 839b307edd
8 changed files with 473 additions and 57 deletions

View File

@@ -107,7 +107,16 @@ export default defineEventHandler(async (event) => {
// Update interest with EOI document information
console.log('[EOI Upload] Updating interest with EOI document info');
await updateInterestEOIDocument(interestId, documentData);
console.log('[EOI Upload] Document data:', JSON.stringify(documentData, null, 2));
try {
await updateInterestEOIDocument(interestId, documentData);
console.log('[EOI Upload] Successfully updated EOI document in database');
} catch (dbError: any) {
console.error('[EOI Upload] Failed to update database with EOI document:', dbError);
console.error('[EOI Upload] Database error details:', dbError.data || dbError.message);
throw new Error(`Failed to update database: ${dbError.message}`);
}
// Update the status fields for uploaded (signed) EOI
const updateData: any = {
@@ -116,18 +125,26 @@ export default defineEventHandler(async (event) => {
'Sales Process Level': 'Signed LOI and NDA'
};
console.log('[EOI Upload] Updating interest status fields for signed EOI');
console.log('[EOI Upload] Status update data:', JSON.stringify(updateData, null, 2));
// Update the interest
await $fetch('/api/update-interest', {
method: 'POST',
headers: {
'x-tag': xTagHeader,
},
body: {
id: interestId,
data: updateData
}
});
try {
// Update the interest
await $fetch('/api/update-interest', {
method: 'POST',
headers: {
'x-tag': xTagHeader,
},
body: {
id: interestId,
data: updateData
}
});
console.log('[EOI Upload] Successfully updated interest status');
} catch (statusError: any) {
console.error('[EOI Upload] Failed to update interest status:', statusError);
console.error('[EOI Upload] Status error details:', statusError.data || statusError.message);
// Don't throw here - the file was uploaded successfully
}
console.log('[EOI Upload] Upload completed successfully');
return {

View File

@@ -4,12 +4,20 @@ import { promises as fs } from 'fs';
import mime from 'mime-types';
export default defineEventHandler(async (event) => {
const xTagHeader = getRequestHeader(event, "x-tag");
if (!xTagHeader || (xTagHeader !== "094ut234" && xTagHeader !== "pjnvü1230")) {
throw createError({ statusCode: 401, statusMessage: "unauthenticated" });
}
try {
// Get the current path and bucket from query params
const query = getQuery(event);
const currentPath = (query.path as string) || '';
const bucket = (query.bucket as string) || 'client-portal'; // Default bucket
console.log('[Upload] Request received for bucket:', bucket, 'path:', currentPath);
// Parse multipart form data
const form = formidable({
maxFileSize: 50 * 1024 * 1024, // 50MB limit
@@ -50,6 +58,15 @@ export default defineEventHandler(async (event) => {
} else {
// For other buckets, use the MinIO client directly
const client = getMinioClient();
// Ensure bucket exists
try {
await client.bucketExists(bucket);
} catch (err) {
console.log(`[Upload] Bucket ${bucket} doesn't exist, creating it...`);
await client.makeBucket(bucket, 'us-east-1');
}
await client.putObject(bucket, fullPath, fileBuffer, fileBuffer.length, {
'Content-Type': contentType,
});