update: domain service

This commit is contained in:
Mahyargdz
2025-05-21 10:27:10 +03:30
parent 9b3b5b41d7
commit e83f7366ca
5 changed files with 28 additions and 194 deletions
+7 -6
View File
@@ -60,15 +60,15 @@ export class AuthService {
try {
await entityManager.begin();
//
const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER");
if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP);
await this.otpService.delOtpFormCache(phone, "REGISTER");
const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password);
const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, business, entityManager);
const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER");
if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP);
await this.otpService.delOtpFormCache(phone, "REGISTER");
const tokens = await this.tokensService.generateTokens(user, entityManager);
await entityManager.commit();
@@ -113,8 +113,9 @@ export class AuthService {
//****************** */
//****************** */
async requestLoginOtp(requestOtpDto: RequestOtpDto, businessId: string, isAdmin: boolean = false) {
async requestLoginOtp(requestOtpDto: RequestOtpDto, businessId: string) {
const { phone } = requestOtpDto;
const user = await this.usersService.findOneWithPhone(phone, businessId);
if (!user) throw new BadRequestException(AuthMessage.PHONE_NOT_FOUND);
@@ -122,7 +123,7 @@ export class AuthService {
const isUserAdmin = this.checkUserIsAdmin(user.role);
if (isAdmin && !isUserAdmin) throw new BadRequestException(AuthMessage.NOT_ADMIN);
if (isUserAdmin) throw new BadRequestException(AuthMessage.NOT_ADMIN);
const existCode = await this.otpService.checkExistOtp(phone, "LOGIN");
if (existCode) {