chore: complete payment service but not tested

This commit is contained in:
mahyargdz
2025-02-04 09:15:22 +03:30
parent 31368610dd
commit 5d91afcc6e
22 changed files with 313 additions and 77 deletions
+25 -10
View File
@@ -1,4 +1,5 @@
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
import { DataSource } from "typeorm";
import { TokensService } from "./tokens.service";
import { AuthMessage, UserMessage } from "../../../common/enums/message.enum";
@@ -20,6 +21,7 @@ export class AuthService {
private readonly passwordService: PasswordService,
private readonly otpService: OTPService,
private readonly tokensService: TokensService,
private readonly dataSource: DataSource,
) {}
//****************** */
//****************** */
@@ -48,20 +50,33 @@ export class AuthService {
//****************** */
async completeRegistration(completeRegistrationDto: CompleteRegistrationDto) {
const { phone, code } = completeRegistrationDto;
const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER");
const queryRunner = this.dataSource.createQueryRunner();
if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP);
await queryRunner.connect();
await queryRunner.startTransaction();
try {
const isValid = await this.otpService.verifyOtp(phone, code, "REGISTER");
await this.otpService.delOtpFormCache(phone, "REGISTER");
const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password);
const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword);
if (!isValid) throw new BadRequestException(AuthMessage.INVALID_OTP);
const tokens = this.tokensService.generateAccessAndRefreshToken({ sub: user.id, role: user.role.name });
await this.otpService.delOtpFormCache(phone, "REGISTER");
const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password);
const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, queryRunner);
return {
message: AuthMessage.USER_REGISTER_SUCCESS,
...tokens,
};
const tokens = this.tokensService.generateAccessAndRefreshToken({ sub: user.id, role: user.role.name });
await queryRunner.commitTransaction();
return {
message: AuthMessage.USER_REGISTER_SUCCESS,
...tokens,
};
} catch (error) {
await queryRunner.rollbackTransaction();
throw error;
} finally {
await queryRunner.release();
}
}
//****************** */
//****************** */