This commit is contained in:
2026-04-16 12:45:31 +03:30
parent 204d29a2f7
commit 5ae39bd082
+95 -85
View File
@@ -1,199 +1,209 @@
import { Controller, Get, Post, Body, Delete, Param, Query, Patch } from '@nestjs/common'; import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
import { ResellerService } from './reseller.service'; import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { ApiOperation } from '@nestjs/swagger';
import { PermissionsDec } from '../../common/decorators/permission.decorator';
import { PermissionEnum } from '../users/enums/permission.enum';
import { CreateResellerDto } from './dto/create-reseller.dto';
import { AuthGuards } from '../../common/decorators/auth-guard.decorator';
import { AdminRoute } from '../../common/decorators/admin.decorator';
import { ResellerRoute } from '../../common/decorators/reseller.decorator';
import { UserDec } from '../../common/decorators/user.decorator';
import { CreateResellerAgentDto } from './dto/create-reseller-agent.dto';
import { SearchWithdrawRequestQueryDto } from './dto/search-withdraw-requests.dto';
import { SearchCustomersDto } from '../users/DTO/search-customers.dto';
import { SearchResellerInvoicesQueryDto } from './dto/search-reseller-invoices.dto';
import { PaginationDto } from '../../common/DTO/pagination.dto';
import { WalletsService } from '../wallets/providers/wallets.service';
import { CreateWithdrawRequestDto } from './dto/create-withdraw-request.dto';
import { CreateUserBankAccountDto } from './dto/create-user-bank-account.dto';
import { ResellerType } from '../auth/DTO/verify-reseller-otp.dto';
import { ConfirmwithdrawRequestDto } from './dto/confirm-withdraw-request.dto';
@Controller('reseller') import { ConfirmwithdrawRequestDto } from "./dto/confirm-withdraw-request.dto";
import { CreateResellerAgentDto } from "./dto/create-reseller-agent.dto";
import { CreateResellerDto } from "./dto/create-reseller.dto";
import { CreateUserBankAccountDto } from "./dto/create-user-bank-account.dto";
import { CreateWithdrawRequestDto } from "./dto/create-withdraw-request.dto";
import { SearchResellerInvoicesQueryDto } from "./dto/search-reseller-invoices.dto";
import { SearchWithdrawRequestQueryDto } from "./dto/search-withdraw-requests.dto";
import { ResellerService } from "./reseller.service";
import { AdminRoute } from "../../common/decorators/admin.decorator";
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
import { Pagination } from "../../common/decorators/pagination.decorator";
import { PermissionsDec } from "../../common/decorators/permission.decorator";
import { ResellerRoute } from "../../common/decorators/reseller.decorator";
import { UserDec } from "../../common/decorators/user.decorator";
import { PaginationDto } from "../../common/DTO/pagination.dto";
import { ParamDto } from "../../common/DTO/param.dto";
import { ResellerType } from "../auth/DTO/verify-reseller-otp.dto";
import { SearchCustomersDto } from "../users/DTO/search-customers.dto";
import { PermissionEnum } from "../users/enums/permission.enum";
import { WalletsService } from "../wallets/providers/wallets.service";
@Controller("reseller")
@AuthGuards() @AuthGuards()
@ApiTags("reseller")
export class ResellerController { export class ResellerController {
constructor( constructor(
private readonly resellerService: ResellerService, private readonly resellerService: ResellerService,
private readonly walletsService: WalletsService, private readonly walletsService: WalletsService,
) { } ) {}
//***************** DSC Endpoints **************** */ //***************** DSC Endpoints **************** */
@ApiOperation({ summary: "create Reseller ==> admin route" }) @ApiOperation({ summary: "Create reseller ==> admin route" })
@AdminRoute() @AdminRoute()
@PermissionsDec(PermissionEnum.RESELLER) @PermissionsDec(PermissionEnum.RESELLER)
@Post() @Post()
createReseller(@Body() dto: CreateResellerDto) { createReseller(@Body() dto: CreateResellerDto) {
return this.resellerService.create(dto) return this.resellerService.create(dto);
} }
@ApiOperation({ summary: "get Resellers ==> admin route" }) @ApiOperation({ summary: "Get resellers ==> admin route" })
@AdminRoute() @AdminRoute()
@PermissionsDec(PermissionEnum.RESELLER) @PermissionsDec(PermissionEnum.RESELLER)
@Get() @Get()
getResellers() { getResellers() {
return this.resellerService.findAll() return this.resellerService.findAll();
} }
//=========== Reward Requests ========= //=========== Reward Requests =========
@ApiOperation({ summary: "get withdraw requests ==> admin route" }) @ApiOperation({ summary: "Get withdraw requests ==> admin route" })
@AdminRoute() @AdminRoute()
@PermissionsDec(PermissionEnum.RESELLER) @PermissionsDec(PermissionEnum.RESELLER)
@Get('withdraw-request/admin') @Pagination()
@Get("withdraw-request/admin")
getRewardRequests(@Query() query: SearchWithdrawRequestQueryDto) { getRewardRequests(@Query() query: SearchWithdrawRequestQueryDto) {
return this.resellerService.getwithdrawRequestsForAdmin(query) return this.resellerService.getwithdrawRequestsForAdmin(query);
} }
@ApiOperation({ summary: "get withdraw requests ==> admin route" }) @ApiOperation({ summary: "Confirm withdraw request ==> admin route" })
@AdminRoute() @AdminRoute()
@PermissionsDec(PermissionEnum.RESELLER) @PermissionsDec(PermissionEnum.RESELLER)
@Patch('withdraw-request/:id') @Patch("withdraw-request/:id")
confirmWithdrawRequests(@Param('id') requestId: string, @Body() dto: ConfirmwithdrawRequestDto) { confirmWithdrawRequests(@Param() paramDto: ParamDto, @Body() dto: ConfirmwithdrawRequestDto) {
return this.resellerService.confirmWithdrawRequest(requestId, dto.transactionId) return this.resellerService.confirmWithdrawRequest(paramDto.id, dto.transactionId);
} }
// ************** Reseller Panel Endpoints *********** // ************** Reseller Panel Endpoints ***********
// =========== Reseller-->Agent ============= // =========== Reseller-->Agent =============
@ApiOperation({ summary: "get Reseller agents ==> reseller route" }) @ApiOperation({ summary: "Get reseller agents ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('agents') @Get("agents")
getResellerAgents(@UserDec("id") userId: string) { getResellerAgents(@UserDec("id") userId: string) {
return this.resellerService.finResellerAgents(userId) return this.resellerService.finResellerAgents(userId);
} }
@ApiOperation({ summary: "Create Reseller agent ==> reseller route" }) @ApiOperation({ summary: "Create reseller agent ==> reseller route" })
@ResellerRoute([ResellerType.reseller]) @ResellerRoute([ResellerType.reseller])
@Post('agents') @Post("agents")
createResellerAgent(@UserDec("id") userId: string, @Body() dto: CreateResellerAgentDto) { createResellerAgent(@UserDec("id") userId: string, @Body() dto: CreateResellerAgentDto) {
return this.resellerService.createResellerAgent(userId, dto.phone) return this.resellerService.createResellerAgent(userId, dto.phone);
} }
@ApiOperation({ summary: "Remove Reseller agent ==> reseller route" }) @ApiOperation({ summary: "Remove reseller agent ==> reseller route" })
@ResellerRoute([ResellerType.reseller]) @ResellerRoute([ResellerType.reseller])
@Delete('agents/:agentId') @Delete("agents/:id")
deleteResellerAgent(@UserDec("id") userId: string, @Param('agentId') agentId: string) { deleteResellerAgent(@UserDec("id") userId: string, @Param() paramDto: ParamDto) {
return this.resellerService.removeResellerAgent(userId, agentId) return this.resellerService.removeResellerAgent(userId, paramDto.id);
} }
// ============ Customers ============= // ============ Customers =============
@ApiOperation({ summary: "get Reseller Customers ==> reseller route" }) @ApiOperation({ summary: "Get reseller customers ==> reseller route" })
@ResellerRoute([ResellerType.reseller]) @ResellerRoute([ResellerType.reseller])
@Get('customers') @Pagination()
@Get("customers")
getCustomers(@UserDec("id") userId: string, @Query() dto: SearchCustomersDto) { getCustomers(@UserDec("id") userId: string, @Query() dto: SearchCustomersDto) {
return this.resellerService.findResellerCustomers(userId, dto) return this.resellerService.findResellerCustomers(userId, dto);
} }
// ============ Invoice =============ok // ============ Invoice =============ok
@ApiOperation({ summary: "get Reseller Customers Invoices==> reseller route" }) @ApiOperation({ summary: "Get reseller customer invoices ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('invoices') @Pagination()
@Get("invoices")
getCustomerInvoices( getCustomerInvoices(
@UserDec("id") userId: string, @UserDec("id") userId: string,
@Query() query: SearchResellerInvoicesQueryDto, @Query() query: SearchResellerInvoicesQueryDto,
@UserDec("resellerType") type: ResellerType @UserDec("resellerType") type: ResellerType,
) { ) {
return this.resellerService.findInvoices(userId, type, query) return this.resellerService.findInvoices(userId, type, query);
} }
// ============ Rewards ============= // ============ Rewards =============
@ApiOperation({ summary: "get Reseller Agents Rewards==> reseller route" }) @ApiOperation({ summary: "Get reseller agent rewards ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('rewards') @Pagination()
@Get("rewards")
getResellerAgentsRewards( getResellerAgentsRewards(
@UserDec("id") userId: string, @UserDec("id") userId: string,
@Query() query: SearchWithdrawRequestQueryDto, @Query() query: SearchWithdrawRequestQueryDto,
@UserDec("resellerType") type: ResellerType @UserDec("resellerType") type: ResellerType,
) { ) {
return this.resellerService.findRewards(userId, type, query) return this.resellerService.findRewards(userId, type, query);
} }
// ============ Wallet Transactions ============= // ============ Wallet Transactions =============
@ApiOperation({ summary: "get Reseller/Agent Wallet Transactions ==> reseller route" }) @ApiOperation({ summary: "Get reseller or agent wallet transactions ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('wallet/transaction') @Pagination()
getWalletTransactionss(@UserDec("id") userId: string, @Query() query: PaginationDto) { @Get("wallet/transaction")
getWalletTransactions(@UserDec("id") userId: string, @Query() query: PaginationDto) {
return this.walletsService.getTransaction(userId, query); return this.walletsService.getTransaction(userId, query);
} }
// ============ Wallet Balance ============= // ============ Wallet Balance =============
@ApiOperation({ summary: "get Reseller/Agent Wallet Balance ==> reseller route" }) @ApiOperation({ summary: "Get reseller or agent wallet balance ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('wallet/balance') @Get("wallet/balance")
getWalletBalance(@UserDec("id") userId: string) { getWalletBalance(@UserDec("id") userId: string) {
return this.walletsService.getBalance(userId) return this.walletsService.getBalance(userId);
} }
// ============Create WithDraw Request ============= // ============Create WithDraw Request =============
@ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" }) @ApiOperation({ summary: "Create reseller or agent withdraw request ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Post('withdraw-request') @Post("withdraw-request")
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 WithDraw Request =============
@ApiOperation({ summary: "remove Reseller/Agent withdraw request ==> reseller route" }) @ApiOperation({ summary: "Remove reseller or agent withdraw request ==> reseller route" })
@ResellerRoute([ResellerType.agent]) @ResellerRoute([ResellerType.agent])
@Delete('withdraw-request/:id') @Delete("withdraw-request/:id")
removeWithdrawRequest(@UserDec("id") userId: string, @Param('id') id: string) { removeWithdrawRequest(@UserDec("id") userId: string, @Param() paramDto: ParamDto) {
return this.resellerService.removeWithdrawRequest(userId, id) return this.resellerService.removeWithdrawRequest(userId, paramDto.id);
} }
// ============ withdraw list============= // ============ withdraw list=============
@ApiOperation({ summary: "Get withdraw-request list ==> reseller route" }) @ApiOperation({ summary: "Get withdraw request list ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('withdraw-request') @Pagination()
getPayments(@UserDec("id") userId: string, @Body() dto: SearchWithdrawRequestQueryDto) { @Get("withdraw-request")
return this.resellerService.getWithdrawRequests(userId, dto) getWithdrawRequests(@UserDec("id") userId: string, @Query() query: SearchWithdrawRequestQueryDto) {
return this.resellerService.getWithdrawRequests(userId, query);
} }
// ============ Create Bank Account ============= // ============ Create Bank Account =============
@ApiOperation({ summary: "Create Bank Account ==> reseller route" }) @ApiOperation({ summary: "Create Bank Account ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Post('bank-account') @Post("bank-account")
createBankAccount(@UserDec("id") userId: string, @Body() dto: CreateUserBankAccountDto) { createBankAccount(@UserDec("id") userId: string, @Body() dto: CreateUserBankAccountDto) {
return this.resellerService.createUserBankAccount(userId, dto) return this.resellerService.createUserBankAccount(userId, dto);
} }
// ============ Get Bank Account ============= // ============ Get Bank Account =============
@ApiOperation({ summary: "Get Bank Account ==> reseller route" }) @ApiOperation({ summary: "Get Bank Account ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('bank-account') @Get("bank-account")
getBankAccount(@UserDec("id") userId: string) { getBankAccount(@UserDec("id") userId: string) {
return this.resellerService.getUserBankAccount(userId) 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([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Delete('bank-account/:id') @Delete("bank-account/:id")
removeBankAccount(@UserDec("id") userId: string, @Param('id') id: string) { removeBankAccount(@UserDec("id") userId: string, @Param() paramDto: ParamDto) {
return this.resellerService.deleteUserBankAccount(userId, id) return this.resellerService.deleteUserBankAccount(userId, paramDto.id);
} }
// ============ Get Referral Codes ============= // ============ Get Referral Codes =============
@ApiOperation({ summary: "Get Referral codes List ==> reseller route" }) @ApiOperation({ summary: "Get referral codes list ==> reseller route" })
@ResellerRoute([ResellerType.agent, ResellerType.reseller]) @ResellerRoute([ResellerType.agent, ResellerType.reseller])
@Get('referral-codes') @Pagination()
getReferalCodesList( @Get("referral-codes")
getReferralCodesList(
@UserDec("id") userId: string, @UserDec("id") userId: string,
@UserDec("resellerType") type: ResellerType, @UserDec("resellerType") type: ResellerType,
@Query() query: PaginationDto @Query() query: PaginationDto,
) { ) {
return this.resellerService.getReferralCodes(userId, type, query) return this.resellerService.getReferralCodes(userId, type, query);
} }
} }