fix filter transaction

This commit is contained in:
Ilham Dwi Pratama S 2021-12-29 09:39:43 +07:00
parent 2948462ff8
commit bd6bf448a6
2 changed files with 9 additions and 12 deletions

View File

@ -117,13 +117,15 @@ export class TransactionController {
async getHistoryTransactionUser( async getHistoryTransactionUser(
@Query('page') page: number, @Query('page') page: number,
@Query('pageSize') pageSize: number, @Query('pageSize') pageSize: number,
@Query('transactionDate') transactionDate: string, @Query('startDate') startDate: string,
@Query('endDate') endDate: string,
@Request() req, @Request() req,
) { ) {
const data = await this.transactionService.transactionHistoryByUser( const data = await this.transactionService.transactionHistoryByUser(
page, page,
req.user.userId, req.user.userId,
transactionDate, startDate,
endDate,
pageSize, pageSize,
); );

View File

@ -765,7 +765,8 @@ export class TransactionService {
async transactionHistoryByUser( async transactionHistoryByUser(
page: number, page: number,
user: string, user: string,
transactionDate: string, startDate: string,
endDate: string,
pageSize?: number, pageSize?: number,
) { ) {
const userData = await this.userService.findExist(user); const userData = await this.userService.findExist(user);
@ -779,12 +780,6 @@ export class TransactionService {
userBySupperior.push(user) userBySupperior.push(user)
} }
if (transactionDate) {
filterTransactionDate = transactionDate.split(',').map((data) => {
return data.trim();
});
}
const baseQuery = this.transactionRepository const baseQuery = this.transactionRepository
.createQueryBuilder('transaction') .createQueryBuilder('transaction')
.select('transaction.id', 'id') .select('transaction.id', 'id')
@ -798,10 +793,10 @@ export class TransactionService {
.addSelect('product.name', 'name') .addSelect('product.name', 'name')
.addSelect('product.id', 'product_id'); .addSelect('product.id', 'product_id');
if (transactionDate && filterTransactionDate.length > 0) { if (startDate && endDate) {
baseQuery.where('transaction.created_at between :startDate and :enDate', { baseQuery.where('transaction.created_at between :startDate and :enDate', {
startDate: filterTransactionDate[0], startDate: new Date(startDate),
enDate: filterTransactionDate[0], enDate: new Date(endDate),
}); });
} }