From ab9e02972e196aa25cc3616a4b98dfd0471944a9 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Thu, 4 Dec 2025 20:01:09 +0530 Subject: [PATCH] Refactor hostCompanyDetails validation schema to make address and location fields optional; update login handler to remove password comparison logic; enhance host service to include user status check and return specific user fields; clean up profile completion logic in MinglarService. --- .../host/hostCompanyDetails.validation.ts | 14 +-- .../handlers/Host_Admin/onboarding/login.ts | 9 -- src/modules/host/services/host.service.ts | 9 ++ .../minglaradmin/services/minglar.service.ts | 87 +++++++++++-------- 4 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/common/utils/validation/host/hostCompanyDetails.validation.ts b/src/common/utils/validation/host/hostCompanyDetails.validation.ts index b98a78e..17d0959 100644 --- a/src/common/utils/validation/host/hostCompanyDetails.validation.ts +++ b/src/common/utils/validation/host/hostCompanyDetails.validation.ts @@ -6,20 +6,20 @@ export const parentCompanySchema = z.object({ .max(100, "Parent company name cannot exceed 100 characters"), address1: z.string() - .min(1, "Address1 is required") - .max(150, "Address1 cannot exceed 150 characters"), + .max(150, "Address1 cannot exceed 150 characters") + .optional(), address2: z.string() .max(150, "Address2 cannot exceed 150 characters") .optional(), - cityXid: z.number().min(1, "City is required"), - stateXid: z.number().min(1, "State is required"), - countryXid: z.number().min(1, "Country is required"), + cityXid: z.number().optional(), + stateXid: z.number().optional(), + countryXid: z.number().optional(), pinCode: z.string() - .min(4, "Pincode/Zipcode is required") - .max(30, "Pincode cannot exceed 30 characters"), + .max(30, "Pincode cannot exceed 30 characters") + .optional(), logoPath: z.string() .max(400, "Logo path cannot exceed 400 characters") diff --git a/src/modules/host/handlers/Host_Admin/onboarding/login.ts b/src/modules/host/handlers/Host_Admin/onboarding/login.ts index 27d7cd4..afc24d0 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/login.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/login.ts @@ -40,15 +40,6 @@ export const handler = safeHandler(async ( throw new ApiError(401, 'Invalid credentials'); } - const matchPassword = await bcrypt.compare( - userPassword, - loginForHost.userPassword - ); - - if (!matchPassword) { - throw new ApiError(401, 'Invalid credentials'); - } - const generateTokenForHost = await tokenService.generateAuthToken( loginForHost.id ); diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 76b3843..c224437 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -291,11 +291,20 @@ export class HostService { async loginForHost(emailAddress: string, userPassword: string) { const existingUser = await this.prisma.user.findUnique({ where: { emailAddress: emailAddress }, + select: { + id: true, + roleXid: true, + userPassword: true, + userStatus: true + } }); if (!existingUser) { throw new ApiError(404, 'User not found'); } + if (existingUser.userStatus == USER_STATUS.REJECTED) { + throw new ApiError(403, "You are not allowed to login. Please contact minglar admin.") + } if (existingUser.roleXid !== 4) { throw new ApiError(403, 'Access denied. Not a host user.'); diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index 2cba1bd..ac5d3df 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -629,50 +629,50 @@ export class MinglarService { } // 5. Calculate profile completion percentage - let percentage = 0; + // let percentage = 0; - // Profile Image: 15% - if (updatedUser.profileImage) percentage += 15; + // // Profile Image: 15% + // if (updatedUser.profileImage) percentage += 15; - // Name and Phone Number: 15% - if ( - updatedUser.firstName && - updatedUser.lastName && - updatedUser.mobileNumber - ) { - percentage += 15; - } + // // Name and Phone Number: 15% + // if ( + // updatedUser.firstName && + // updatedUser.lastName && + // updatedUser.mobileNumber + // ) { + // percentage += 15; + // } - // Location Info: 25% - if (updatedUser.userAddressDetails.length > 0) { - const address = updatedUser.userAddressDetails[0]; - if ( - address.address1 && - address.stateXid && - address.countryXid && - address.cityXid && - address.pinCode - ) { - percentage += 25; - } - } + // // Location Info: 25% + // if (updatedUser.userAddressDetails.length > 0) { + // const address = updatedUser.userAddressDetails[0]; + // if ( + // address.address1 && + // address.stateXid && + // address.countryXid && + // address.cityXid && + // address.pinCode + // ) { + // percentage += 25; + // } + // } - // Documents: 45% - if (updatedUser.userDocuments.length >= 2) { - percentage += 45; - } else if (updatedUser.userDocuments.length === 1) { - percentage += 22.5; - } + // // Documents: 45% + // if (updatedUser.userDocuments.length >= 2) { + // percentage += 45; + // } else if (updatedUser.userDocuments.length === 1) { + // percentage += 22.5; + // } - const profilePercentage = Math.min(percentage, 100); + // const profilePercentage = Math.min(percentage, 100); // Update profile completion status - if (profilePercentage > 80) { - await tx.user.update({ - where: { id: userId }, - data: { isProfileUpdated: true }, - }); - } + // if (profilePercentage > 75) { + await tx.user.update({ + where: { id: userId }, + data: { isProfileUpdated: true }, + }); + // } console.log('Transaction completed successfully'); @@ -687,7 +687,6 @@ export class MinglarService { }, address: updatedUser.userAddressDetails[0] || null, documents: updatedUser.userDocuments, - profileCompletionPercentage: profilePercentage, }; }); } catch (error) { @@ -1222,6 +1221,18 @@ export class MinglarService { hostCountMap[uid] = g._count.id; }); + for (const user of users) { + const am = user.profileImage; + + if (user?.profileImage) { + const key = user.profileImage.startsWith('http') + ? user.profileImage.split('.com/')[1] + : user.profileImage; + + user.profileImage = await getPresignedUrl(bucket, key); + } + } + // 4. Attach host counts to each user return users.map((user) => ({ ...user,