feat: add page size in all the rest API
This commit is contained in:
@@ -1,17 +1,4 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
Request,
|
||||
HttpStatus,
|
||||
Query,
|
||||
Put,
|
||||
ParseUUIDPipe,
|
||||
} from '@nestjs/common';
|
||||
import { Body, Controller, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query, Request } from '@nestjs/common';
|
||||
import { TransactionService } from './transaction.service';
|
||||
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
||||
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
||||
@@ -101,10 +88,15 @@ export class TransactionController {
|
||||
}
|
||||
|
||||
@Get('history')
|
||||
async findByCategories(@Query('page') page: number, @Request() req) {
|
||||
async findByCategories(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Request() req,
|
||||
) {
|
||||
const data = await this.transactionService.transactionHistoryByUser(
|
||||
page,
|
||||
req.user.userId,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -115,11 +107,16 @@ export class TransactionController {
|
||||
}
|
||||
|
||||
@Get('deposit-return')
|
||||
async findDepositReturn(@Query('page') page: number, @Request() req) {
|
||||
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 {
|
||||
@@ -133,12 +130,14 @@ export class TransactionController {
|
||||
@Get('deposit-return/confirmation')
|
||||
async findDepositReturnConfirmation(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Request() req,
|
||||
) {
|
||||
const [data, count] =
|
||||
await this.transactionService.getAllDepositReturnToUser(
|
||||
req.user.userId,
|
||||
page,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,24 +3,14 @@ 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,
|
||||
EntityManager,
|
||||
EntityNotFoundError,
|
||||
Repository,
|
||||
} from 'typeorm';
|
||||
import { Connection, EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
||||
import { CoaService } from './coa.service';
|
||||
import * as uuid from 'uuid';
|
||||
import { uniq } from 'lodash';
|
||||
import { Decimal } from 'decimal.js';
|
||||
import {
|
||||
balanceType,
|
||||
coaType,
|
||||
statusTransaction,
|
||||
typeTransaction,
|
||||
} from '../helper/enum-list';
|
||||
import { balanceType, coaType, statusTransaction, typeTransaction } from '../helper/enum-list';
|
||||
import { ProductService } from '../product/product.service';
|
||||
import { CreateJournalDto } from './dto/create-journal.dto';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
@@ -560,7 +550,11 @@ export class TransactionService {
|
||||
return transactionData;
|
||||
}
|
||||
|
||||
async transactionHistoryByUser(page: number, user: string) {
|
||||
async transactionHistoryByUser(
|
||||
page: number,
|
||||
user: string,
|
||||
pageSize?: number,
|
||||
) {
|
||||
const baseQuery = this.transactionRepository
|
||||
.createQueryBuilder('transaction')
|
||||
.select('transaction.id', 'id')
|
||||
@@ -578,8 +572,8 @@ export class TransactionService {
|
||||
// .leftJoinAndSelect('product_price.product', 'product');
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.offset(page * (pageSize || 10))
|
||||
.limit(pageSize || 10)
|
||||
.getRawMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
@@ -614,10 +608,14 @@ export class TransactionService {
|
||||
}
|
||||
}
|
||||
|
||||
async getAllDepositReturnFromUser(user: string, page: number) {
|
||||
async getAllDepositReturnFromUser(
|
||||
user: string,
|
||||
page: number,
|
||||
pageSize?: number,
|
||||
) {
|
||||
return this.transactionRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
skip: page * (pageSize || 10),
|
||||
take: pageSize || 10,
|
||||
where: {
|
||||
user: user,
|
||||
type: typeTransaction.DEPOSIT_RETURN,
|
||||
@@ -628,10 +626,14 @@ export class TransactionService {
|
||||
});
|
||||
}
|
||||
|
||||
async getAllDepositReturnToUser(user: string, page: number) {
|
||||
async getAllDepositReturnToUser(
|
||||
user: string,
|
||||
page: number,
|
||||
pageSize?: number,
|
||||
) {
|
||||
return this.transactionRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
skip: page * (pageSize || 10),
|
||||
take: pageSize || 10,
|
||||
where: {
|
||||
user_destination: user,
|
||||
type: typeTransaction.DEPOSIT_RETURN,
|
||||
|
||||
Reference in New Issue
Block a user