add: filter deposit return

This commit is contained in:
ilham 2022-01-05 14:08:29 +07:00
parent 928e7a51ae
commit 68cd326ca4
2 changed files with 42 additions and 27 deletions

View File

@ -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,

View File

@ -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({
skip: page * (pageSize || 10),
take: pageSize || 10,
where: {
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: filter,
order: {
createdAt: 'DESC',
},
});
return baseQuery;
}
async getAllDepositReturnToUser(