chore: add referral logic to first payment

This commit is contained in:
mahyargdz
2025-04-15 14:54:33 +03:30
parent a5976a3377
commit bd4d9dbf0d
7 changed files with 92 additions and 8 deletions
+10 -1
View File
@@ -4,6 +4,7 @@ import { DataSource } from "typeorm";
import { TokensService } from "./tokens.service";
import { AuthMessage, UserMessage } from "../../../common/enums/message.enum";
import { NotificationsService } from "../../notifications/providers/notifications.service";
import { ReferralsService } from "../../referrals/providers/referrals.service";
import { Role } from "../../users/entities/role.entity";
import { UsersService } from "../../users/providers/users.service";
import { OTPService } from "../../utils/providers/otp.service";
@@ -25,6 +26,7 @@ export class AuthService {
private readonly dataSource: DataSource,
private readonly notificationService: NotificationsService,
private readonly smsService: SmsService,
private readonly referralsService: ReferralsService,
) {}
//****************** */
//****************** */
@@ -51,7 +53,7 @@ export class AuthService {
//****************** */
//****************** */
async completeRegistration(completeRegistrationDto: CompleteRegistrationDto) {
const { phone, code } = completeRegistrationDto;
const { phone, code, referralCode } = completeRegistrationDto;
const queryRunner = this.dataSource.createQueryRunner();
await queryRunner.connect();
@@ -65,6 +67,13 @@ export class AuthService {
const hashedPassword = await this.passwordService.hashPassword(completeRegistrationDto.password);
const user = await this.usersService.createUser(completeRegistrationDto, hashedPassword, queryRunner);
if (referralCode) {
await this.referralsService.useReferralCode({
referralCode,
userId: user.id,
});
}
const tokens = await this.tokensService.generateTokens(user, queryRunner);
await queryRunner.commitTransaction();