From 86c5e87e8b9404a9c5a92c3811521cda72b6f9dd Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Wed, 15 Apr 2026 12:50:24 +0330 Subject: [PATCH] new endpoints --- .../referral-rewards.repository.ts | 3 ++- .../withdraw-request.repository.ts | 17 ++++++++++--- src/modules/reseller/reseller.controller.ts | 25 ++++++++++++++++--- src/modules/reseller/reseller.service.ts | 19 ++++++++++++-- src/modules/users/providers/users.service.ts | 12 ++++++--- 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/modules/referrals/repositories/referral-rewards.repository.ts b/src/modules/referrals/repositories/referral-rewards.repository.ts index bb05b12..268ddf2 100755 --- a/src/modules/referrals/repositories/referral-rewards.repository.ts +++ b/src/modules/referrals/repositories/referral-rewards.repository.ts @@ -14,8 +14,9 @@ export class ReferralRewardsRepository extends Repository { async findPaginatedList(userIds: string[], queryDto: SearchRewardsRequestQueryDto) { const { limit, skip } = PaginationUtils(queryDto); + console.log(userIds) const qb = this.createQueryBuilder("rr") - .where("rr.userId IN (:...userIds)", { userIds }) + // .where("rr.userId IN (:...userIds)", { userIds }) .leftJoinAndSelect("rr.user", "user") .orderBy("rr.createdAt", "DESC") .skip(skip) diff --git a/src/modules/reseller/repositories/withdraw-request.repository.ts b/src/modules/reseller/repositories/withdraw-request.repository.ts index 8672a9f..d81eda3 100755 --- a/src/modules/reseller/repositories/withdraw-request.repository.ts +++ b/src/modules/reseller/repositories/withdraw-request.repository.ts @@ -11,13 +11,24 @@ export class WithdrawRequestRepository extends Repository super(repository.target, repository.manager, repository.queryRunner); } - async findPaginatedList(queryDto: SearchRewardsRequestQueryDto) { + async findPaginatedListForAdmin(queryDto: SearchRewardsRequestQueryDto) { const { limit, skip } = PaginationUtils(queryDto); const queryBuilder = this.createQueryBuilder("request") .leftJoinAndSelect("request.user", "user") - .orderBy("ticket.createdAt", "DESC"); - + .orderBy("ticket.createdAt", "DESC"); + + return queryBuilder.skip(skip).take(limit).getManyAndCount(); + } + + async findPaginatedList(userId: string, queryDto: SearchRewardsRequestQueryDto) { + const { limit, skip } = PaginationUtils(queryDto); + + const queryBuilder = this.createQueryBuilder("request") + .where("request.user.id = :userId", { userId }) + .leftJoinAndSelect("request.user", "user") + .orderBy("ticket.createdAt", "DESC"); + return queryBuilder.skip(skip).take(limit).getManyAndCount(); } } diff --git a/src/modules/reseller/reseller.controller.ts b/src/modules/reseller/reseller.controller.ts index a15f0d9..49ea9c9 100644 --- a/src/modules/reseller/reseller.controller.ts +++ b/src/modules/reseller/reseller.controller.ts @@ -116,22 +116,30 @@ export class ResellerController { return this.walletsService.getBalance(userId) } - // ============ WithDraw Request ============= + // ============Payment WithDraw Request ============= @ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" }) @ResellerRoute() - @Post('wallet/withdraw') + @Post('payment/withdraw') withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) { return this.resellerService.createWithdrawRequest(userId, dto.amount) } - // ============ Remove WithDraw Request ============= + // ============ Remove payment WithDraw Request ============= @ApiOperation({ summary: "remove Reseller/Agent withdraw request ==> reseller route" }) @ResellerRoute() - @Delete('wallet/withdraw/:id') + @Delete('paymant/withdraw/:id') removeWithdrawRequest(@UserDec("id") userId: string, @Param('id') id: string) { return this.resellerService.removeWithdrawRequest(userId, id) } + // ============ Payment list============= + @ApiOperation({ summary: "Get Payment list ==> reseller route" }) + @ResellerRoute() + @Get('payment') + getPayments(@UserDec("id") userId: string, @Body() dto: SearchRewardsRequestQueryDto) { + return this.resellerService.getRewrdsRequests(userId, dto) + } + // ============ Bank Account ============= @ApiOperation({ summary: "Create Bank Account ==> reseller route" }) @ResellerRoute() @@ -140,6 +148,15 @@ export class ResellerController { return this.resellerService.createUserBankAccount(userId, dto) } + + // ============ Get Bank Account ============= + @ApiOperation({ summary: "Get Bank Account ==> reseller route" }) + @ResellerRoute() + @Get('bank-account') + getBankAccount(@UserDec("id") userId: string) { + return this.resellerService.getUserBankAccount(userId) + } + // ============ Remove Bank Account ============= @ApiOperation({ summary: "remove User Bank account ==> reseller route" }) @ResellerRoute() diff --git a/src/modules/reseller/reseller.service.ts b/src/modules/reseller/reseller.service.ts index 52d0d75..eb3fe5d 100644 --- a/src/modules/reseller/reseller.service.ts +++ b/src/modules/reseller/reseller.service.ts @@ -127,9 +127,16 @@ export class ResellerService { return this.referralService.findRewards(agentIds, query) } - async getRewrdsRequests(queryDto: SearchRewardsRequestQueryDto) { + async getRewrdsRequestsForAdmin(queryDto: SearchRewardsRequestQueryDto) { - const [requests, count] = await this.withdrawRequestRepository.findPaginatedList(queryDto); + const [requests, count] = await this.withdrawRequestRepository.findPaginatedListForAdmin(queryDto); + + return { requests, count, paginate: true }; + } + + async getRewrdsRequests(userId: string, queryDto: SearchRewardsRequestQueryDto) { + + const [requests, count] = await this.withdrawRequestRepository.findPaginatedList(userId, queryDto); return { requests, count, paginate: true }; } @@ -168,6 +175,14 @@ export class ResellerService { return this.withdrawRequestRepository.remove(request) } + //********* Bank Account ***********/ + async getUserBankAccount(userId: string) { + + return this.userBankAccountRepository.find({ + where: { user: { id: userId } } + }) + } + //********* Bank Account ***********/ async createUserBankAccount(userId: string, dto: CreateUserBankAccountDto) { const { user } = await this.usersService.findOneById(userId) diff --git a/src/modules/users/providers/users.service.ts b/src/modules/users/providers/users.service.ts index 251c387..8a8cdd9 100755 --- a/src/modules/users/providers/users.service.ts +++ b/src/modules/users/providers/users.service.ts @@ -1,6 +1,6 @@ import { createHmac, randomBytes } from "node:crypto"; -import { BadRequestException, HttpStatus, Injectable, Logger } from "@nestjs/common"; +import { BadRequestException, HttpStatus, Injectable, Logger, NotFoundException } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { FastifyReply } from "fastify"; import slugify from "slugify"; @@ -373,14 +373,20 @@ export class UsersService { async getResellerByUserPhone(phone: string) { const reseller = await this.userRepository.findOne({ where: { ownedReseller: { owner: { phone } } } }); - return { reseller }; + if (!reseller) { + throw new NotFoundException() + } + return reseller } /************************************************************ */ async getAgentByUserPhone(phone: string) { const agent = await this.userRepository.findOne({ where: { reseller: { agents: { phone } } } }); - return { agent }; + if (!agent) { + throw new NotFoundException() + } + return agent }