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"),
|
.max(100, "Parent company name cannot exceed 100 characters"),
|
||||||
|
|
||||||
address1: z.string()
|
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()
|
address2: z.string()
|
||||||
.max(150, "Address2 cannot exceed 150 characters")
|
.max(150, "Address2 cannot exceed 150 characters")
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|
||||||
cityXid: z.number().min(1, "City is required"),
|
cityXid: z.number().optional(),
|
||||||
stateXid: z.number().min(1, "State is required"),
|
stateXid: z.number().optional(),
|
||||||
countryXid: z.number().min(1, "Country is required"),
|
countryXid: z.number().optional(),
|
||||||
|
|
||||||
pinCode: z.string()
|
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()
|
logoPath: z.string()
|
||||||
.max(400, "Logo path cannot exceed 400 characters")
|
.max(400, "Logo path cannot exceed 400 characters")
|
||||||
|
|||||||
@@ -40,15 +40,6 @@ export const handler = safeHandler(async (
|
|||||||
throw new ApiError(401, 'Invalid credentials');
|
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(
|
const generateTokenForHost = await tokenService.generateAuthToken(
|
||||||
loginForHost.id
|
loginForHost.id
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -291,11 +291,20 @@ export class HostService {
|
|||||||
async loginForHost(emailAddress: string, userPassword: string) {
|
async loginForHost(emailAddress: string, userPassword: string) {
|
||||||
const existingUser = await this.prisma.user.findUnique({
|
const existingUser = await this.prisma.user.findUnique({
|
||||||
where: { emailAddress: emailAddress },
|
where: { emailAddress: emailAddress },
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
roleXid: true,
|
||||||
|
userPassword: true,
|
||||||
|
userStatus: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
throw new ApiError(404, 'User not found');
|
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) {
|
if (existingUser.roleXid !== 4) {
|
||||||
throw new ApiError(403, 'Access denied. Not a host user.');
|
throw new ApiError(403, 'Access denied. Not a host user.');
|
||||||
|
|||||||
@@ -629,50 +629,50 @@ export class MinglarService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 5. Calculate profile completion percentage
|
// 5. Calculate profile completion percentage
|
||||||
let percentage = 0;
|
// let percentage = 0;
|
||||||
|
|
||||||
// Profile Image: 15%
|
// // Profile Image: 15%
|
||||||
if (updatedUser.profileImage) percentage += 15;
|
// if (updatedUser.profileImage) percentage += 15;
|
||||||
|
|
||||||
// Name and Phone Number: 15%
|
// // Name and Phone Number: 15%
|
||||||
if (
|
// if (
|
||||||
updatedUser.firstName &&
|
// updatedUser.firstName &&
|
||||||
updatedUser.lastName &&
|
// updatedUser.lastName &&
|
||||||
updatedUser.mobileNumber
|
// updatedUser.mobileNumber
|
||||||
) {
|
// ) {
|
||||||
percentage += 15;
|
// percentage += 15;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Location Info: 25%
|
// // Location Info: 25%
|
||||||
if (updatedUser.userAddressDetails.length > 0) {
|
// if (updatedUser.userAddressDetails.length > 0) {
|
||||||
const address = updatedUser.userAddressDetails[0];
|
// const address = updatedUser.userAddressDetails[0];
|
||||||
if (
|
// if (
|
||||||
address.address1 &&
|
// address.address1 &&
|
||||||
address.stateXid &&
|
// address.stateXid &&
|
||||||
address.countryXid &&
|
// address.countryXid &&
|
||||||
address.cityXid &&
|
// address.cityXid &&
|
||||||
address.pinCode
|
// address.pinCode
|
||||||
) {
|
// ) {
|
||||||
percentage += 25;
|
// percentage += 25;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Documents: 45%
|
// // Documents: 45%
|
||||||
if (updatedUser.userDocuments.length >= 2) {
|
// if (updatedUser.userDocuments.length >= 2) {
|
||||||
percentage += 45;
|
// percentage += 45;
|
||||||
} else if (updatedUser.userDocuments.length === 1) {
|
// } else if (updatedUser.userDocuments.length === 1) {
|
||||||
percentage += 22.5;
|
// percentage += 22.5;
|
||||||
}
|
// }
|
||||||
|
|
||||||
const profilePercentage = Math.min(percentage, 100);
|
// const profilePercentage = Math.min(percentage, 100);
|
||||||
|
|
||||||
// Update profile completion status
|
// Update profile completion status
|
||||||
if (profilePercentage > 80) {
|
// if (profilePercentage > 75) {
|
||||||
await tx.user.update({
|
await tx.user.update({
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
data: { isProfileUpdated: true },
|
data: { isProfileUpdated: true },
|
||||||
});
|
});
|
||||||
}
|
// }
|
||||||
|
|
||||||
console.log('Transaction completed successfully');
|
console.log('Transaction completed successfully');
|
||||||
|
|
||||||
@@ -687,7 +687,6 @@ export class MinglarService {
|
|||||||
},
|
},
|
||||||
address: updatedUser.userAddressDetails[0] || null,
|
address: updatedUser.userAddressDetails[0] || null,
|
||||||
documents: updatedUser.userDocuments,
|
documents: updatedUser.userDocuments,
|
||||||
profileCompletionPercentage: profilePercentage,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1222,6 +1221,18 @@ export class MinglarService {
|
|||||||
hostCountMap[uid] = g._count.id;
|
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
|
// 4. Attach host counts to each user
|
||||||
return users.map((user) => ({
|
return users.map((user) => ({
|
||||||
...user,
|
...user,
|
||||||
|
|||||||
Reference in New Issue
Block a user