new endpoints
This commit is contained in:
@@ -14,8 +14,9 @@ export class ReferralRewardsRepository extends Repository<ReferralReward> {
|
|||||||
|
|
||||||
async findPaginatedList(userIds: string[], queryDto: SearchRewardsRequestQueryDto) {
|
async findPaginatedList(userIds: string[], queryDto: SearchRewardsRequestQueryDto) {
|
||||||
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")
|
||||||
.orderBy("rr.createdAt", "DESC")
|
.orderBy("rr.createdAt", "DESC")
|
||||||
.skip(skip)
|
.skip(skip)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class WithdrawRequestRepository extends Repository<RewardWithdrawRequest>
|
|||||||
super(repository.target, repository.manager, repository.queryRunner);
|
super(repository.target, repository.manager, repository.queryRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findPaginatedList(queryDto: SearchRewardsRequestQueryDto) {
|
async findPaginatedListForAdmin(queryDto: SearchRewardsRequestQueryDto) {
|
||||||
const { limit, skip } = PaginationUtils(queryDto);
|
const { limit, skip } = PaginationUtils(queryDto);
|
||||||
|
|
||||||
const queryBuilder = this.createQueryBuilder("request")
|
const queryBuilder = this.createQueryBuilder("request")
|
||||||
@@ -20,4 +20,15 @@ export class WithdrawRequestRepository extends Repository<RewardWithdrawRequest>
|
|||||||
|
|
||||||
return queryBuilder.skip(skip).take(limit).getManyAndCount();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,22 +116,30 @@ export class ResellerController {
|
|||||||
return this.walletsService.getBalance(userId)
|
return this.walletsService.getBalance(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ WithDraw Request =============
|
// ============Payment WithDraw Request =============
|
||||||
@ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" })
|
@ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" })
|
||||||
@ResellerRoute()
|
@ResellerRoute()
|
||||||
@Post('wallet/withdraw')
|
@Post('payment/withdraw')
|
||||||
withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) {
|
withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) {
|
||||||
return this.resellerService.createWithdrawRequest(userId, dto.amount)
|
return this.resellerService.createWithdrawRequest(userId, dto.amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ Remove WithDraw Request =============
|
// ============ Remove payment WithDraw Request =============
|
||||||
@ApiOperation({ summary: "remove Reseller/Agent withdraw request ==> reseller route" })
|
@ApiOperation({ summary: "remove Reseller/Agent withdraw request ==> reseller route" })
|
||||||
@ResellerRoute()
|
@ResellerRoute()
|
||||||
@Delete('wallet/withdraw/:id')
|
@Delete('paymant/withdraw/:id')
|
||||||
removeWithdrawRequest(@UserDec("id") userId: string, @Param('id') id: string) {
|
removeWithdrawRequest(@UserDec("id") userId: string, @Param('id') id: string) {
|
||||||
return this.resellerService.removeWithdrawRequest(userId, id)
|
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 =============
|
// ============ Bank Account =============
|
||||||
@ApiOperation({ summary: "Create Bank Account ==> reseller route" })
|
@ApiOperation({ summary: "Create Bank Account ==> reseller route" })
|
||||||
@ResellerRoute()
|
@ResellerRoute()
|
||||||
@@ -140,6 +148,15 @@ export class ResellerController {
|
|||||||
return this.resellerService.createUserBankAccount(userId, dto)
|
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 =============
|
// ============ Remove Bank Account =============
|
||||||
@ApiOperation({ summary: "remove User Bank account ==> reseller route" })
|
@ApiOperation({ summary: "remove User Bank account ==> reseller route" })
|
||||||
@ResellerRoute()
|
@ResellerRoute()
|
||||||
|
|||||||
@@ -127,9 +127,16 @@ export class ResellerService {
|
|||||||
return this.referralService.findRewards(agentIds, query)
|
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 };
|
return { requests, count, paginate: true };
|
||||||
}
|
}
|
||||||
@@ -168,6 +175,14 @@ export class ResellerService {
|
|||||||
return this.withdrawRequestRepository.remove(request)
|
return this.withdrawRequestRepository.remove(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//********* Bank Account ***********/
|
||||||
|
async getUserBankAccount(userId: string) {
|
||||||
|
|
||||||
|
return this.userBankAccountRepository.find({
|
||||||
|
where: { user: { id: userId } }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//********* Bank Account ***********/
|
//********* Bank Account ***********/
|
||||||
async createUserBankAccount(userId: string, dto: CreateUserBankAccountDto) {
|
async createUserBankAccount(userId: string, dto: CreateUserBankAccountDto) {
|
||||||
const { user } = await this.usersService.findOneById(userId)
|
const { user } = await this.usersService.findOneById(userId)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createHmac, randomBytes } from "node:crypto";
|
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 { ConfigService } from "@nestjs/config";
|
||||||
import { FastifyReply } from "fastify";
|
import { FastifyReply } from "fastify";
|
||||||
import slugify from "slugify";
|
import slugify from "slugify";
|
||||||
@@ -373,14 +373,20 @@ export class UsersService {
|
|||||||
|
|
||||||
async getResellerByUserPhone(phone: string) {
|
async getResellerByUserPhone(phone: string) {
|
||||||
const reseller = await this.userRepository.findOne({ where: { ownedReseller: { owner: { phone } } } });
|
const reseller = await this.userRepository.findOne({ where: { ownedReseller: { owner: { phone } } } });
|
||||||
return { reseller };
|
if (!reseller) {
|
||||||
|
throw new NotFoundException()
|
||||||
|
}
|
||||||
|
return reseller
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************ */
|
/************************************************************ */
|
||||||
|
|
||||||
async getAgentByUserPhone(phone: string) {
|
async getAgentByUserPhone(phone: string) {
|
||||||
const agent = await this.userRepository.findOne({ where: { reseller: { agents: { phone } } } });
|
const agent = await this.userRepository.findOne({ where: { reseller: { agents: { phone } } } });
|
||||||
return { agent };
|
if (!agent) {
|
||||||
|
throw new NotFoundException()
|
||||||
|
}
|
||||||
|
return agent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user