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