From 46daec00ce4e986deea8699bad711482ddc5f9c8 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Tue, 16 Dec 2025 14:37:38 +0530 Subject: [PATCH] fixed the keytooloong issue --- .../onboarding/submitCompanyDetails.ts | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts b/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts index 513d982..675770a 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts @@ -17,6 +17,16 @@ import { sendEmailToAM, sendEmailToMinglarAdmin } from '../../../services/sendHo const hostService = new HostService(prismaClient); +function getExtensionFromMime(mimeType: string) { + const map: Record = { + 'image/jpeg': 'jpg', + 'image/png': 'png', + 'application/pdf': 'pdf', + 'image/webp': 'webp', + }; + return map[mimeType] || 'bin'; +} + const s3 = new AWS.S3({ region: config.aws.region, }); @@ -284,11 +294,10 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise< } } - - /** 11) UPLOAD DOCUMENTS */ async function uploadToS3(buffer, mimeType, originalName, folderType, documentTypeXid?, fieldName?) { - const ext = originalName.split('.').pop() || 'jpg'; + // const ext = originalName.split('.').pop() || 'jpg'; + const ext = getExtensionFromMime(mimeType); let s3Key = ''; @@ -362,28 +371,40 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise< } /** UPLOAD LOGO (if provided) */ - const logoFile = files.find((f) => f.fieldName === 'companyLogo' || f.fieldName === 'companyLogoFile'); - if (logoFile) { - const logoUrl = await uploadToS3(logoFile.buffer, logoFile.mimeType, logoFile.fileName, 'logo'); + const logoFile = files.find( + (f) => f.fieldName === 'companyLogo' || f.fieldName === 'companyLogoFile' + ); + + if (logoFile && logoFile.buffer && logoFile.fileName) { + const logoUrl = await uploadToS3( + logoFile.buffer, + logoFile.mimeType, + logoFile.fileName, + 'logo' + ); parsedCompany.logoPath = logoUrl; } /** UPLOAD PARENT COMPANY LOGO (if provided) */ - const parentLogoFile = files.find((f) => f.fieldName === 'parentCompanyLogo'); - if (parentLogoFile) { + const parentLogoFile = files.find( + (f) => f.fieldName === 'parentCompanyLogo' + ); + + if (parentLogoFile && parentLogoFile.buffer && parentLogoFile.mimeType) { + // 🔒 Only upload when an actual file is present const parentLogoUrl = await uploadToS3( parentLogoFile.buffer, parentLogoFile.mimeType, - parentLogoFile.fileName, + parentLogoFile.fileName, // safe here because it's a real file 'parent_company_logo', ); if (parsedParentCompany) { parsedParentCompany.logoPath = parentLogoUrl; } else { - // if no parent object exists yet (drafts or other flows), attach it safely - parsedParentCompany = parsedParentCompany || {}; - parsedParentCompany.logoPath = parentLogoUrl; + parsedParentCompany = { + logoPath: parentLogoUrl, + }; } }