diff --git a/src/transaction/transaction.controller.ts b/src/transaction/transaction.controller.ts index 69151b9..ab90dae 100644 --- a/src/transaction/transaction.controller.ts +++ b/src/transaction/transaction.controller.ts @@ -169,27 +169,6 @@ export class TransactionController { }; } - @Get('deposit-return') - async findDepositReturn( - @Query('page') page: number, - @Query('pageSize') pageSize: number, - @Request() req, - ) { - const [data, count] = - await this.transactionService.getAllDepositReturnFromUser( - req.user.userId, - page, - pageSize, - ); - - return { - data, - count, - statusCode: HttpStatus.OK, - message: 'success', - }; - } - @Get('total-order') async findTotalOrder(@Request() req) { const data = await this.transactionService.getTotalSell(req.user); @@ -223,6 +202,31 @@ export class TransactionController { }; } + @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, diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index b96e9c5..07aa5ad 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -3,7 +3,7 @@ import { DistributeTransactionDto } from './dto/distribute-transaction.dto'; import { OrderTransactionDto } from './dto/order-transaction.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { Transactions } from './entities/transactions.entity'; -import { Connection, EntityNotFoundError, Repository } from 'typeorm'; +import { Between, Connection, EntityNotFoundError, Repository } from 'typeorm'; import { COA } from './entities/coa.entity'; import { TransactionJournal } from './entities/transaction-journal.entity'; import { CoaService } from './coa.service'; @@ -1001,19 +1001,30 @@ export class TransactionService { async getAllDepositReturnFromUser( user: string, page: number, + startDate: string, + endDate: string, pageSize?: number, ) { - return this.transactionRepository.findAndCount({ + const filter = { + user: user, + type: typeTransaction.DEPOSIT_RETURN, + }; + + if (startDate && endDate) { + filter['start'] = Between(new Date(startDate), new Date(endDate)); + } + const baseQuery = this.transactionRepository.findAndCount({ skip: page * (pageSize || 10), take: pageSize || 10, - where: { - user: user, - type: typeTransaction.DEPOSIT_RETURN, - }, + where: filter, order: { createdAt: 'DESC', }, }); + + + + return baseQuery; } async getAllDepositReturnToUser(