210 lines
8.5 KiB
TypeScript
210 lines
8.5 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from "@nestjs/common";
|
|
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
|
|
|
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()
|
|
@ApiTags("reseller")
|
|
export class ResellerController {
|
|
constructor(
|
|
private readonly resellerService: ResellerService,
|
|
private readonly walletsService: WalletsService,
|
|
) {}
|
|
|
|
//***************** DSC Endpoints **************** */
|
|
@ApiOperation({ summary: "Create reseller ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER_CREATE)
|
|
@Post()
|
|
createReseller(@Body() dto: CreateResellerDto) {
|
|
return this.resellerService.create(dto);
|
|
}
|
|
|
|
@ApiOperation({ summary: "Get resellers ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER_READ)
|
|
@Get()
|
|
getResellers() {
|
|
return this.resellerService.findAll();
|
|
}
|
|
|
|
//=========== Reward Requests =========
|
|
|
|
@ApiOperation({ summary: "Get withdraw requests ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER_READ)
|
|
@Pagination()
|
|
@Get("withdraw-request/admin")
|
|
getRewardRequests(@Query() query: SearchWithdrawRequestQueryDto) {
|
|
return this.resellerService.getwithdrawRequestsForAdmin(query);
|
|
}
|
|
|
|
@ApiOperation({ summary: "Confirm withdraw request ==> admin route" })
|
|
@AdminRoute()
|
|
@PermissionsDec(PermissionEnum.RESELLER_UPDATE)
|
|
@Patch("withdraw-request/:id")
|
|
confirmWithdrawRequests(@Param() paramDto: ParamDto, @Body() dto: ConfirmwithdrawRequestDto) {
|
|
return this.resellerService.confirmWithdrawRequest(paramDto.id, 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/:id")
|
|
deleteResellerAgent(@UserDec("id") userId: string, @Param() paramDto: ParamDto) {
|
|
return this.resellerService.removeResellerAgent(userId, paramDto.id);
|
|
}
|
|
|
|
// ============ Customers =============
|
|
@ApiOperation({ summary: "Get reseller customers ==> reseller route" })
|
|
@ResellerRoute([ResellerType.reseller])
|
|
@Pagination()
|
|
@Get("customers")
|
|
getCustomers(@UserDec("id") userId: string, @Query() dto: SearchCustomersDto) {
|
|
return this.resellerService.findResellerCustomers(userId, dto);
|
|
}
|
|
|
|
// ============ Invoice =============ok
|
|
@ApiOperation({ summary: "Get reseller customer invoices ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Pagination()
|
|
@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 agent rewards ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Pagination()
|
|
@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 or agent wallet transactions ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Pagination()
|
|
@Get("wallet/transaction")
|
|
getWalletTransactions(@UserDec("id") userId: string, @Query() query: PaginationDto) {
|
|
return this.walletsService.getTransaction(userId, query);
|
|
}
|
|
|
|
// ============ Wallet Balance =============
|
|
|
|
@ApiOperation({ summary: "Get reseller or 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 or 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 or agent withdraw request ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent])
|
|
@Delete("withdraw-request/:id")
|
|
removeWithdrawRequest(@UserDec("id") userId: string, @Param() paramDto: ParamDto) {
|
|
return this.resellerService.removeWithdrawRequest(userId, paramDto.id);
|
|
}
|
|
|
|
// ============ withdraw list=============
|
|
@ApiOperation({ summary: "Get withdraw request list ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Pagination()
|
|
@Get("withdraw-request")
|
|
getWithdrawRequests(@UserDec("id") userId: string, @Query() query: SearchWithdrawRequestQueryDto) {
|
|
return this.resellerService.getWithdrawRequests(userId, query);
|
|
}
|
|
|
|
// ============ 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() paramDto: ParamDto) {
|
|
return this.resellerService.deleteUserBankAccount(userId, paramDto.id);
|
|
}
|
|
|
|
// ============ Get Referral Codes =============
|
|
@ApiOperation({ summary: "Get referral codes list ==> reseller route" })
|
|
@ResellerRoute([ResellerType.agent, ResellerType.reseller])
|
|
@Pagination()
|
|
@Get("referral-codes")
|
|
getReferralCodesList(
|
|
@UserDec("id") userId: string,
|
|
@UserDec("resellerType") type: ResellerType,
|
|
@Query() query: PaginationDto,
|
|
) {
|
|
return this.resellerService.getReferralCodes(userId, type, query);
|
|
}
|
|
}
|