first
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { Request } from "express";
|
||||
import { inject } from "inversify";
|
||||
import { controller, httpGet, httpPost, request, requestBody } from "inversify-express-utils";
|
||||
|
||||
import { WalletService } from "./wallet.service";
|
||||
import { HttpStatus } from "../../common";
|
||||
import { WithdrawDTO } from "./DTO/withdraw.dto";
|
||||
import { BaseController } from "../../common/base/controller";
|
||||
import { ApiAuth, ApiModel, ApiOperation, ApiResponse, ApiTags } from "../../common/decorator/swggerDocs";
|
||||
import { Guard } from "../../core/middlewares/guard.middleware";
|
||||
import { ValidationMiddleware } from "../../core/middlewares/validator.middleware";
|
||||
import { IOCTYPES } from "../../IOC/ioc.types";
|
||||
import { ISeller } from "../seller/models/Abstraction/ISeller";
|
||||
|
||||
@controller("/wallet")
|
||||
@ApiTags("Wallet")
|
||||
class WalletController extends BaseController {
|
||||
@inject(IOCTYPES.WalletService) walletService: WalletService;
|
||||
|
||||
@ApiOperation("get all transaction of seller wallet ==> login as seller")
|
||||
@ApiResponse("successful", HttpStatus.Ok)
|
||||
@ApiAuth()
|
||||
@httpGet("/transaction", Guard.authSeller())
|
||||
public async getTransactions(@request() req: Request) {
|
||||
const seller = req.user as ISeller;
|
||||
const data = await this.walletService.getTransactions(seller._id.toString());
|
||||
return this.response(data);
|
||||
}
|
||||
|
||||
@ApiOperation("Get wallet balance ==> login as seller")
|
||||
@ApiResponse("Successful", HttpStatus.Ok)
|
||||
@ApiAuth()
|
||||
@httpGet("/balance", Guard.authSeller())
|
||||
public async getWalletBalance(@request() req: Request) {
|
||||
const seller = req.user as ISeller;
|
||||
const balance = await this.walletService.getWalletBalance(seller._id.toString());
|
||||
return this.response(balance);
|
||||
}
|
||||
|
||||
@ApiOperation("Get all seller withdrawal requests ==> login as seller")
|
||||
@ApiResponse("Successful", HttpStatus.Ok)
|
||||
@ApiAuth()
|
||||
@httpGet("/withdraw", Guard.authSeller())
|
||||
public async getWithdrawalRequests(@request() req: Request) {
|
||||
const seller = req.user as ISeller;
|
||||
const data = await this.walletService.getWithdrawalRequests(seller._id.toString());
|
||||
return this.response(data);
|
||||
}
|
||||
|
||||
@ApiOperation("withdraw request for seller wallet ==> login as seller")
|
||||
@ApiResponse("Successful", HttpStatus.Created)
|
||||
@ApiResponse("Insufficient balance or withdrawal failed", HttpStatus.BadRequest)
|
||||
@ApiModel(WithdrawDTO)
|
||||
@ApiAuth()
|
||||
@httpPost("/withdraw", Guard.authSeller(), ValidationMiddleware.validateInput(WithdrawDTO))
|
||||
public async withdrawRequest(@request() req: Request, @requestBody() withdrawDto: WithdrawDTO) {
|
||||
const seller = req.user as ISeller;
|
||||
const data = await this.walletService.withdrawRequest(seller, withdrawDto.amount);
|
||||
return this.response(data, HttpStatus.Created);
|
||||
}
|
||||
}
|
||||
|
||||
export { WalletController };
|
||||
Reference in New Issue
Block a user