refactor: enhance customer creation code

This commit is contained in:
Abdalhamid Alhamad
2025-01-13 16:42:27 +03:00
parent 221f3bae4f
commit 5aa3d3774d
6 changed files with 70 additions and 66 deletions

View File

@ -61,7 +61,7 @@ export class AuthService {
this.logger.log(`Verifying user with phone number ${verifyUserDto.countryCode + verifyUserDto.phoneNumber}`);
const user = await this.userService.findUserOrThrow({ phoneNumber: verifyUserDto.phoneNumber });
if (user.isPasswordSet) {
if (user.isProfileCompleted) {
this.logger.error(
`User with phone number ${verifyUserDto.countryCode + verifyUserDto.phoneNumber} already verified`,
);
@ -82,7 +82,18 @@ export class AuthService {
throw new BadRequestException('USERS.INVALID_OTP');
}
const updatedUser = await this.userService.verifyUserAndCreateCustomer(user);
if (user.isPhoneVerified) {
this.logger.log(
`User with phone number ${
verifyUserDto.countryCode + verifyUserDto.phoneNumber
} already verified but did not complete registration process`,
);
const tokens = await this.generateAuthToken(user);
return [tokens, user];
}
const updatedUser = await this.userService.verifyUserAndCreateCustomer(user.id);
const tokens = await this.generateAuthToken(updatedUser);
this.logger.log(