200 lines
8.2 KiB
TypeScript
200 lines
8.2 KiB
TypeScript
import { Controller, Get, Post, Body, Delete, Param, Query, Patch } from '@nestjs/common';
|
|
import { ResellerService } from './reseller.service';
|
|
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')
|
|
@AuthGuards()
|
|
export class ResellerController {
|
|
constructor(
|
|
private readonly resellerService: ResellerService,
|
|
private readonly walletsService: WalletsService,
|
|
) { }
|
|
|
|
//***************** DSC Endpoints **************** */
|
|
@ApiOperation({ summary: "create Reseller ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER)
|
|
@Post()
|
|
createReseller(@Body() dto: CreateResellerDto) {
|
|
return this.resellerService.create(dto)
|
|
}
|
|
|
|
@ApiOperation({ summary: "get Resellers ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER)
|
|
@Get()
|
|
getResellers() {
|
|
return this.resellerService.findAll()
|
|
}
|
|
|
|
//=========== Reward Requests =========
|
|
|
|
@ApiOperation({ summary: "get withdraw requests ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER)
|
|
@Get('withdraw-request/admin')
|
|
getRewardRequests(@Query() query: SearchWithdrawRequestQueryDto) {
|
|
return this.resellerService.getwithdrawRequestsForAdmin(query)
|
|
}
|
|
|
|
@ApiOperation({ summary: "get withdraw requests ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER)
|
|
@Patch('withdraw-request/:id')
|
|
confirmWithdrawRequests(@Param('id') requestId: string, @Body() dto: ConfirmwithdrawRequestDto) {
|
|
return this.resellerService.confirmWithdrawRequest(requestId, dto.transactionId)
|
|
}
|
|
|
|
// ************** Reseller Panel Endpoints ***********
|
|
|
|
// =========== Reseller-->Agent =============
|
|
|
|
@ApiOperation({ summary: "get Reseller agents ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('agents')
|
|
getResellerAgents(@UserDec("id") userId: string) {
|
|
return this.resellerService.finResellerAgents(userId)
|
|
}
|
|
|
|
@ApiOperation({ summary: "Create Reseller agent ==> reseller route" })
|
|
@ResellerRoute([ResellerType.reseller])
|
|
@Post('agents')
|
|
createResellerAgent(@UserDec("id") userId: string, @Body() dto: CreateResellerAgentDto) {
|
|
return this.resellerService.createResellerAgent(userId, dto.phone)
|
|
}
|
|
|
|
@ApiOperation({ summary: "Remove Reseller agent ==> reseller route" })
|
|
@ResellerRoute([ResellerType.reseller])
|
|
@Delete('agents/:agentId')
|
|
deleteResellerAgent(@UserDec("id") userId: string, @Param('agentId') agentId: string) {
|
|
return this.resellerService.removeResellerAgent(userId, agentId)
|
|
}
|
|
|
|
// ============ Customers =============
|
|
@ApiOperation({ summary: "get Reseller Customers ==> reseller route" })
|
|
@ResellerRoute([ResellerType.reseller])
|
|
@Get('customers')
|
|
getCustomers(@UserDec("id") userId: string, @Query() dto: SearchCustomersDto) {
|
|
return this.resellerService.findResellerCustomers(userId, dto)
|
|
}
|
|
|
|
// ============ Invoice =============ok
|
|
@ApiOperation({ summary: "get Reseller Customers Invoices==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('invoices')
|
|
getCustomerInvoices(
|
|
@UserDec("id") userId: string,
|
|
@Query() query: SearchResellerInvoicesQueryDto,
|
|
@UserDec("resellerType") type: ResellerType
|
|
) {
|
|
return this.resellerService.findInvoices(userId, type, query)
|
|
}
|
|
|
|
// ============ Rewards =============
|
|
@ApiOperation({ summary: "get Reseller Agents Rewards==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('rewards')
|
|
getResellerAgentsRewards(
|
|
@UserDec("id") userId: string,
|
|
@Query() query: SearchWithdrawRequestQueryDto,
|
|
@UserDec("resellerType") type: ResellerType
|
|
) {
|
|
return this.resellerService.findRewards(userId, type, query)
|
|
}
|
|
|
|
// ============ Wallet Transactions =============
|
|
@ApiOperation({ summary: "get Reseller/Agent Wallet Transactions ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('wallet/transaction')
|
|
getWalletTransactionss(@UserDec("id") userId: string, @Query() query: PaginationDto) {
|
|
return this.walletsService.getTransaction(userId, query);
|
|
}
|
|
|
|
// ============ Wallet Balance =============
|
|
|
|
@ApiOperation({ summary: "get Reseller/Agent Wallet Balance ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('wallet/balance')
|
|
getWalletBalance(@UserDec("id") userId: string) {
|
|
return this.walletsService.getBalance(userId)
|
|
}
|
|
|
|
// ============Create WithDraw Request =============
|
|
@ApiOperation({ summary: "Create Reseller/Agent withdraw request ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Post('withdraw-request')
|
|
withdrawRequest(@UserDec("id") userId: string, @Body() dto: CreateWithdrawRequestDto) {
|
|
return this.resellerService.createWithdrawRequest(userId, dto.amount)
|
|
}
|
|
|
|
// ============ Remove WithDraw Request =============
|
|
@ApiOperation({ summary: "remove Reseller/Agent withdraw request ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent])
|
|
@Delete('withdraw-request/:id')
|
|
removeWithdrawRequest(@UserDec("id") userId: string, @Param('id') id: string) {
|
|
return this.resellerService.removeWithdrawRequest(userId, id)
|
|
}
|
|
|
|
// ============ withdraw list=============
|
|
@ApiOperation({ summary: "Get withdraw-request list ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('withdraw-request')
|
|
getPayments(@UserDec("id") userId: string, @Body() dto: SearchWithdrawRequestQueryDto) {
|
|
return this.resellerService.getWithdrawRequests(userId, dto)
|
|
}
|
|
|
|
// ============ Create Bank Account =============
|
|
@ApiOperation({ summary: "Create Bank Account ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Post('bank-account')
|
|
createBankAccount(@UserDec("id") userId: string, @Body() dto: CreateUserBankAccountDto) {
|
|
return this.resellerService.createUserBankAccount(userId, dto)
|
|
}
|
|
|
|
// ============ Get Bank Account =============
|
|
@ApiOperation({ summary: "Get Bank Account ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@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([ResellerType.agent, ResellerType.reseller])
|
|
@Delete('bank-account/:id')
|
|
removeBankAccount(@UserDec("id") userId: string, @Param('id') id: string) {
|
|
return this.resellerService.deleteUserBankAccount(userId, id)
|
|
}
|
|
|
|
// ============ Get Referral Codes =============
|
|
@ApiOperation({ summary: "Get Referral codes List ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Get('referral-codes')
|
|
getReferalCodesList(
|
|
@UserDec("id") userId: string,
|
|
@UserDec("resellerType") type: ResellerType,
|
|
@Query() query: PaginationDto
|
|
) {
|
|
return this.resellerService.getReferralCodes(userId, type, query)
|
|
}
|
|
|
|
}
|