fix :bugs
This commit is contained in:
@@ -13,8 +13,11 @@ export class ReferralCodesRepository extends Repository<ReferralCode> {
|
||||
}
|
||||
|
||||
async findPaginatedList(userIds: string[], queryDto: PaginationDto) {
|
||||
if (!userIds.length) {
|
||||
return [[], 0] as [ReferralCode[], number];
|
||||
}
|
||||
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
console.log(userIds)
|
||||
const qb = this.createQueryBuilder("rr")
|
||||
.where("rr.userId IN (:...userIds)", { userIds })
|
||||
.leftJoinAndSelect("rr.user", "user")
|
||||
|
||||
@@ -13,6 +13,10 @@ export class ReferralRewardsRepository extends Repository<ReferralReward> {
|
||||
}
|
||||
|
||||
async findPaginatedList(userIds: string[], queryDto: SearchWithdrawRequestQueryDto) {
|
||||
if (!userIds.length) {
|
||||
return [[], 0] as [ReferralReward[], number];
|
||||
}
|
||||
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
const qb = this.createQueryBuilder("rr")
|
||||
.where("rr.userId IN (:...userIds)", { userIds })
|
||||
|
||||
@@ -12,6 +12,11 @@ export class ReferralsRepository extends Repository<Referral> {
|
||||
}
|
||||
|
||||
async findPaginatedList(userIds: string[], queryDto: SearchCustomersQueryDto) {
|
||||
|
||||
if (userIds.length == 0) {
|
||||
return [[], 0]
|
||||
}
|
||||
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const qb = this.createQueryBuilder("referral")
|
||||
|
||||
@@ -16,7 +16,7 @@ export class RewardWithdrawRequest extends BaseEntity {
|
||||
@Column({ type: "timestamp", nullable: true })
|
||||
paidAt: Date;
|
||||
|
||||
@Column({ type: "varchar", length: 255, nullable: true })
|
||||
@Column({ type: "varchar", length: 255, nullable: true, unique: true })
|
||||
transactionId?: string;
|
||||
|
||||
@OneToMany(() => WalletTransaction, (walletTransaction) => walletTransaction.withdrawRequest)
|
||||
|
||||
@@ -95,10 +95,18 @@ export class ResellerService {
|
||||
return user
|
||||
}
|
||||
|
||||
async removeResellerAgent(userId: string, agentToBeDeleted: string) {
|
||||
await this.FindOneOrFailByUserId(userId)
|
||||
async removeResellerAgent(userId: string, agentId: string) {
|
||||
const reseller = await this.FindOneOrFailByUserId(userId)
|
||||
|
||||
const { user } = await this.usersService.findOneById(agentId)
|
||||
|
||||
const { user } = await this.usersService.findOneById(agentToBeDeleted)
|
||||
if (!user) {
|
||||
throw new NotFoundException(AuthMessage.USER_NOT_FOUND)
|
||||
}
|
||||
|
||||
if (user.reseller?.id !== reseller.id) {
|
||||
throw new BadRequestException("بازاریاب به این نمایندگی تعلق ندارد")
|
||||
}
|
||||
|
||||
user.reseller = undefined
|
||||
|
||||
@@ -112,15 +120,19 @@ export class ResellerService {
|
||||
|
||||
const agentIds = reselller.agents.map(ag => ag.id)
|
||||
|
||||
if (!agentIds.length) {
|
||||
return { customers: [], count: 0, paginate: true };
|
||||
}
|
||||
|
||||
return this.referralService.findPaginatedReferedUsers(agentIds, query)
|
||||
}
|
||||
|
||||
// *************** Invoice ***************
|
||||
async findInvoices(userId: string, type: ResellerType, query: SearchResellerInvoicesQueryDto) {
|
||||
if (type == ResellerType.agent) {
|
||||
return this.findResellerCustomersInvoices(userId, query)
|
||||
} else if (type == ResellerType.reseller) {
|
||||
return this.findAgentCustomersInvoices(userId, query)
|
||||
} else if (type == ResellerType.reseller) {
|
||||
return this.findResellerCustomersInvoices(userId, query)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +141,10 @@ export class ResellerService {
|
||||
|
||||
const agentIds = reselller.agents.map(ag => ag.id)
|
||||
|
||||
if (!agentIds.length) {
|
||||
return { invoices: [], count: 0, paginate: true };
|
||||
}
|
||||
|
||||
const customerIds = await this.referralService.findReferedUsersIds(agentIds)
|
||||
|
||||
const [invoices, count] = await this.invoicesService.findInvoicesByCustomerIds(customerIds, query)
|
||||
@@ -163,6 +179,10 @@ export class ResellerService {
|
||||
|
||||
const agentIds = reselller.agents.map(ag => ag.id)
|
||||
|
||||
if (!agentIds.length) {
|
||||
return { rewards: [], count: 0, paginate: true };
|
||||
}
|
||||
|
||||
return this.referralService.findRewards(agentIds, query)
|
||||
}
|
||||
|
||||
@@ -234,7 +254,7 @@ export class ResellerService {
|
||||
return this.withdrawRequestRepository.remove(request)
|
||||
}
|
||||
|
||||
async confirmWithdrawRequest(requestId: string,transactionId:string) {
|
||||
async confirmWithdrawRequest(requestId: string, transactionId: string) {
|
||||
const request = await this.withdrawRequestRepository.findOne({ where: { id: requestId }, relations: ['user'] })
|
||||
if (!request) {
|
||||
throw new BadRequestException("درخواست برداشت یافت نشد .")
|
||||
@@ -326,11 +346,15 @@ export class ResellerService {
|
||||
|
||||
const agentIds = reselller.agents.map(ag => ag.id)
|
||||
|
||||
return this.referralService.findRewards(agentIds, query)
|
||||
if (!agentIds.length) {
|
||||
return { codes: [], count: 0, paginate: true };
|
||||
}
|
||||
|
||||
return this.referralService.getReferralCodesByUserIds(agentIds, query)
|
||||
}
|
||||
|
||||
private async findAgentReferralCodes(userId: string, query: SearchWithdrawRequestQueryDto) {
|
||||
return this.referralService.findRewards([userId], query)
|
||||
return this.referralService.getReferralCodesByUserIds([userId], query)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user