add : referral codes list
This commit is contained in:
@@ -13,6 +13,7 @@ import { ReferralRewardsRepository } from "../repositories/referral-rewards.repo
|
||||
import { ReferralsRepository } from "../repositories/referrals.repository";
|
||||
import { SearchCustomersDto } from "../../users/DTO/search-customers.dto";
|
||||
import { SearchWithdrawRequestQueryDto } from "../../reseller/dto/search-withdraw-requests.dto";
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
@Injectable()
|
||||
export class ReferralsService {
|
||||
private MAX_ATTEMPTS = 10;
|
||||
@@ -152,8 +153,14 @@ export class ReferralsService {
|
||||
|
||||
async findRewards(userIds: string[], query: SearchWithdrawRequestQueryDto) {
|
||||
|
||||
const [data, count] = await this.referralRewardsRepository.findPaginatedList(userIds, query);
|
||||
const [rewards, count] = await this.referralRewardsRepository.findPaginatedList(userIds, query);
|
||||
|
||||
return { data, count, paginate: true };
|
||||
return { rewards, count, paginate: true };
|
||||
}
|
||||
|
||||
async getReferralCodesByUserIds(userIds: string[], query: PaginationDto) {
|
||||
const [codes, count] = await this.referralCodesRepository.findPaginatedList(userIds, query);
|
||||
|
||||
return { codes, count, paginate: true };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,25 @@ import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { ReferralCode } from "../entities/referral-code.entity";
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
|
||||
@Injectable()
|
||||
export class ReferralCodesRepository extends Repository<ReferralCode> {
|
||||
constructor(@InjectRepository(ReferralCode) repository: Repository<ReferralCode>) {
|
||||
super(repository.target, repository.manager, repository.queryRunner);
|
||||
}
|
||||
|
||||
async findPaginatedList(userIds: string[], queryDto: PaginationDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
console.log(userIds)
|
||||
const qb = this.createQueryBuilder("rr")
|
||||
.where("rr.userId IN (:...userIds)", { userIds })
|
||||
.leftJoinAndSelect("rr.user", "user")
|
||||
.orderBy("rr.createdAt", "DESC")
|
||||
.skip(skip)
|
||||
.take(limit);
|
||||
|
||||
return qb.getManyAndCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,6 @@ export class ResellerController {
|
||||
return this.resellerService.createUserBankAccount(userId, dto)
|
||||
}
|
||||
|
||||
|
||||
// ============ Get Bank Account =============
|
||||
@ApiOperation({ summary: "Get Bank Account ==> reseller route" })
|
||||
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
||||
@@ -176,4 +175,16 @@ export class ResellerController {
|
||||
return this.resellerService.deleteUserBankAccount(userId, id)
|
||||
}
|
||||
|
||||
// ============ Get Referral Codes =============
|
||||
@ApiOperation({ summary: "Get Referral codes List ==> reseller route" })
|
||||
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
||||
@Get('referral-codes')
|
||||
getReferalCodesList(
|
||||
@UserDec("id") userId: string,
|
||||
@UserDec("resellerType") type: ResellerType,
|
||||
@Query() query: PaginationDto
|
||||
) {
|
||||
return this.resellerService.getReferralCodes(userId, type, query)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { SearchResellerInvoicesQueryDto } from './dto/search-reseller-invoices.d
|
||||
import { CreateUserBankAccountDto } from './dto/create-user-bank-account.dto';
|
||||
import { UserBankAccountRepository } from './repositories/user-bank-account.repository';
|
||||
import { ResellerType } from '../auth/DTO/verify-reseller-otp.dto';
|
||||
import { PaginationDto } from '../../common/DTO/pagination.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ResellerService {
|
||||
@@ -148,6 +149,7 @@ export class ResellerService {
|
||||
return this.findResellerAgentsRewards(userId, query)
|
||||
}
|
||||
}
|
||||
|
||||
async findResellerAgentsRewards(userId: string, query: SearchWithdrawRequestQueryDto) {
|
||||
const reselller = await this.FindOneOrFailByUserId(userId)
|
||||
|
||||
@@ -238,4 +240,26 @@ export class ResellerService {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//*********** Referral Code ************/
|
||||
async getReferralCodes(userId: string, type: ResellerType, query: PaginationDto) {
|
||||
if (type == ResellerType.agent) {
|
||||
return this.findAgentReferralCodes(userId, query)
|
||||
} else if (type == ResellerType.reseller) {
|
||||
return this.findResellerAgentsReferralCodes(userId, query)
|
||||
}
|
||||
}
|
||||
|
||||
private async findResellerAgentsReferralCodes(userId: string, query: SearchWithdrawRequestQueryDto) {
|
||||
const reselller = await this.FindOneOrFailByUserId(userId)
|
||||
|
||||
const agentIds = reselller.agents.map(ag => ag.id)
|
||||
|
||||
return this.referralService.findRewards(agentIds, query)
|
||||
}
|
||||
|
||||
private async findAgentReferralCodes(userId: string, query: SearchWithdrawRequestQueryDto) {
|
||||
return this.referralService.findRewards([userId], query)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user