import { Body, Controller, Get, Header, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query, Request, Res } from '@nestjs/common'; import { TransactionService } from './transaction.service'; import { DistributeTransactionDto } from './dto/distribute-transaction.dto'; import { OrderTransactionDto } from './dto/order-transaction.dto'; import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto'; import { DepositReturnDto } from './dto/deposit_return.dto'; import { ExportTransactionDto } from './dto/export-transaction.dto'; @Controller({ path: 'transaction', version: '1', }) export class TransactionController { constructor(private readonly transactionService: TransactionService) {} @Post('distribute') async create( @Body() createTransactionDto: DistributeTransactionDto, @Request() req, ) { return { data: await this.transactionService.distributeDeposit( createTransactionDto, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('distribute-admin') async distributeAdmin( @Body() createTransactionDto: DistributeTransactionDto, @Request() req, ) { return { data: await this.transactionService.distributeFromAdmin( createTransactionDto, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('add-saldo-supplier') async addSaldoSupplier( @Body() addSaldoSupplier: AddSaldoSupplier, @Request() req, ) { return { data: await this.transactionService.addSupplierSaldo( addSaldoSupplier, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('order') async orderTransaction( @Body() orderTransactionDto: OrderTransactionDto, @Request() req, ) { return { data: await this.transactionService.orderTransaction( orderTransactionDto, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('order-prod') async orderTransactionProd( @Body() orderTransactionDto: OrderTransactionDto, @Request() req, ) { return { data: await this.transactionService.orderTransactionProd( orderTransactionDto, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('order-bill-prod') async orderTransactioBillnProd( @Body() orderTransactionDto: OrderTransactionDto, @Request() req, ) { return { data: await this.transactionService.orderTransactionBillProd( orderTransactionDto, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('check-bill') async checkBill( @Body() orderTransactionDto: OrderTransactionDto, @Request() req, ) { return { data: await this.transactionService.checkBill( orderTransactionDto, req.user, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('deposit-return') async depositReturn( @Body() depositReturnDto: DepositReturnDto, @Request() req, ) { return { data: await this.transactionService.createDepositReturn( req.user, depositReturnDto, ), statusCode: HttpStatus.CREATED, message: 'success', }; } @Post('rollback-jurnal') async rollbackJurnal(@Body() request, @Request() req) { const data = await this.transactionService.rollbackJurnal(request.trxId); return { data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('resend-partner/success/:code') async resendSuccess(@Request() req, @Param('code') code: string) { const data = await this.transactionService.resendOrderToPartner(code, true); return { data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('resend-partner/failed/:code') async resendFailed(@Request() req, @Param('code') code: string) { const data = await this.transactionService.resendOrderToPartner( code, false, ); return { data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('history') async getHistoryTransactionUser( @Query('page') page: number, @Query('pageSize') pageSize: number, @Query('start') startDate: string, @Query('end') endDate: string, @Request() req, ) { const data = await this.transactionService.transactionHistoryByUser( page, req.user.userId, startDate == 'null' ? null : startDate, endDate == 'null' ? null : endDate, pageSize, ); return { ...data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('check-bill-history') async getCheckBillHistory( @Param('id') id: string, @Query('page') page: number, @Query('pageSize') pageSize: number, @Request() req, ) { const [data, count] = await this.transactionService.findAll( req.user.userId, page, pageSize, ); return { data, count, statusCode: HttpStatus.OK, message: 'success', }; } @Get('history-user/:id') async getHistoryTransactionUserByParam( @Query('page') page: number, @Query('pageSize') pageSize: number, @Query('start') startDate: string, @Query('end') endDate: string, @Param('id', ParseUUIDPipe) id: string, ) { const data = await this.transactionService.transactionHistoryByUser( page, id, startDate == 'null' ? null : startDate, endDate == 'null' ? null : endDate, pageSize, ); return { ...data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('history-deposit') async getHistoryDepositUser( @Query('page') page: number, @Query('pageSize') pageSize: number, @Query('user-destination') userDestination: string, @Request() req, ) { const data = await this.transactionService.topUpHistoryByUser( page, req.user.userId, userDestination, 'detail', pageSize, ); return { ...data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('history-deposit-profile') async getHistoryDepositUserProfile( @Query('page') page: number, @Query('pageSize') pageSize: number, @Query('user-destination') userDestination: string, @Request() req, ) { const data = await this.transactionService.topUpHistoryByUser( page, req.user.userId, userDestination, 'profile', pageSize, ); return { ...data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('total-order') async findTotalOrder(@Request() req) { const data = await this.transactionService.getTotalSell(req.user); return { data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('total-order-b2b') async findTotalOrderB2B(@Request() req) { const data = await this.transactionService.getTotalSellB2B(req.user); return { data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('total-order-partner') async findTotalOrderPartner(@Request() req) { const data = await this.transactionService.getTotalSellPartner(req.user); return { data, statusCode: HttpStatus.OK, message: 'success', }; } @Get('deposit-return') async findDepositReturn( @Query('page') page: number, @Query('pageSize') pageSize: number, @Query('start') startDate: string, @Query('end') endDate: string, @Request() req, ) { const [data, count] = await this.transactionService.getAllDepositReturnFromUser( req.user.userId, page, startDate == 'null' ? null : startDate, endDate == 'null' ? null : endDate, pageSize, ); return { data, count, statusCode: HttpStatus.OK, message: 'success', }; } @Get('deposit-return/confirmation') async findDepositReturnConfirmation( @Query('page') page: number, @Query('pageSize') pageSize: number, @Query('start') startDate: string, @Query('end') endDate: string, @Query('sender') sender: string, @Request() req, ) { const data = await this.transactionService.getAllDepositReturnToUser( req.user.userId, page, sender == 'null' ? null : sender, startDate == 'null' ? null : startDate, endDate == 'null' ? null : endDate, pageSize, ); return { ...data, statusCode: HttpStatus.OK, message: 'success', }; } @Put('deposit-return/confirmation/:id/:status') async confirmDepositReturn( @Param('id', ParseUUIDPipe) id: string, @Param('status') status: string, @Request() req, ) { return { data: await this.transactionService.confirmationDepositReturn( id, req.user, status, ), statusCode: HttpStatus.OK, message: 'success', }; } @Put('deposit-return/confirmation-admin/:id') async confirmDepositReturnAdmin( @Param('id', ParseUUIDPipe) id: string, @Request() req, @Body() status: string, ) { return { data: await this.transactionService.confirmationAdminDepositReturn( id, req.user, status, ), statusCode: HttpStatus.OK, message: 'success', }; } @Put('withdraw/:id') async withdrawProfit(@Param('id', ParseUUIDPipe) id: string, @Request() req) { return { data: await this.transactionService.withdrawBenefit(id), statusCode: HttpStatus.OK, message: 'success', }; } }