add : referral codes list

This commit is contained in:
2026-04-15 16:24:03 +03:30
parent 6e8e2cd527
commit 36c01fe01c
4 changed files with 60 additions and 3 deletions
+12 -1
View File
@@ -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)
}
}
+24
View File
@@ -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)
}
}