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.
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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.');
|
||||
|
||||
@@ -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) {
|
||||
// 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,
|
||||
|
||||
Reference in New Issue
Block a user