feat: add page size in all the rest API
This commit is contained in:
@@ -38,6 +38,7 @@ export class ProductHistoryPriceService {
|
||||
page: number,
|
||||
productId: string,
|
||||
supplierId: string,
|
||||
pageSize?: number,
|
||||
) {
|
||||
try {
|
||||
const query = this.productHistoryPriceService
|
||||
@@ -54,8 +55,8 @@ export class ProductHistoryPriceService {
|
||||
|
||||
const data = await query
|
||||
.orderBy('product_history_price.createdAt', 'DESC')
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.skip(page * (pageSize || 10))
|
||||
.take(pageSize || 10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await query.getCount();
|
||||
|
||||
@@ -36,10 +36,10 @@ export class ProductCategoriesService {
|
||||
);
|
||||
}
|
||||
|
||||
findAll(page) {
|
||||
findAll(page, pageSize?) {
|
||||
return this.productCategoriesRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
skip: page * (pageSize || 10),
|
||||
take: pageSize || 10,
|
||||
order: {
|
||||
version: 'DESC',
|
||||
},
|
||||
|
||||
@@ -44,7 +44,7 @@ export class ProductSubCategoriesService {
|
||||
);
|
||||
}
|
||||
|
||||
async findAll(page, category: string) {
|
||||
async findAll(page, category: string, pageSize?) {
|
||||
let filterCategories;
|
||||
if (category) {
|
||||
filterCategories = category.split(',').map((data) => data.trim());
|
||||
@@ -61,8 +61,8 @@ export class ProductSubCategoriesService {
|
||||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.skip(page * (pageSize || 10))
|
||||
.take(pageSize || 10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
@@ -72,6 +72,7 @@ export class ProductController {
|
||||
@Get('all')
|
||||
async findAll(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('sub-category') subcategory: string,
|
||||
@Query('supplier') supplier: string,
|
||||
) {
|
||||
@@ -79,6 +80,7 @@ export class ProductController {
|
||||
page,
|
||||
supplier == 'null' ? null : supplier,
|
||||
subcategory == 'null' ? null : subcategory,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -105,6 +107,7 @@ export class ProductController {
|
||||
@Get('by-categories-all')
|
||||
async findByCategoriesAll(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('sub-category') subcategory: string,
|
||||
@Query('supplier') supplier: string,
|
||||
) {
|
||||
@@ -112,6 +115,7 @@ export class ProductController {
|
||||
page,
|
||||
subcategory,
|
||||
supplier,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -143,8 +147,14 @@ export class ProductController {
|
||||
}
|
||||
|
||||
@Get('categories')
|
||||
async findAllCategories(@Query('page') page: number) {
|
||||
const [data, count] = await this.productCategoriesService.findAll(page);
|
||||
async findAllCategories(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
) {
|
||||
const [data, count] = await this.productCategoriesService.findAll(
|
||||
page,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
data,
|
||||
@@ -157,11 +167,13 @@ export class ProductController {
|
||||
@Get('sub-categories')
|
||||
async findAllSubCategories(
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('category') category: string,
|
||||
) {
|
||||
const data = await this.productSubCategoriesService.findAll(
|
||||
page,
|
||||
category == 'null' ? null : category,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -184,12 +196,14 @@ export class ProductController {
|
||||
async findPriceHistoryByProductId(
|
||||
@Param('id', ParseUUIDPipe) id: string,
|
||||
@Query('page') page: number,
|
||||
@Query('pageSize') pageSize: number,
|
||||
@Query('supplier') supplier: string,
|
||||
) {
|
||||
const data = await this.productHistoryPriceService.findOneByProductId(
|
||||
page,
|
||||
id,
|
||||
supplier,
|
||||
pageSize,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -47,7 +47,12 @@ export class ProductService {
|
||||
return this.productRepository.findOneOrFail(result.identifiers[0].id);
|
||||
}
|
||||
|
||||
async findAll(page: number, supplier: string, subCategories: string) {
|
||||
async findAll(
|
||||
page: number,
|
||||
supplier: string,
|
||||
subCategories: string,
|
||||
pageSize?: number,
|
||||
) {
|
||||
let filterSupplier, filterSubCategories;
|
||||
|
||||
if (supplier) {
|
||||
@@ -61,10 +66,6 @@ export class ProductService {
|
||||
return data.trim();
|
||||
});
|
||||
}
|
||||
// if (supplier.length > 0) {
|
||||
// const dataSupplier = await this.supplierService.findByActiveAll();
|
||||
// supplier = dataSupplier.map((item) => item.id);
|
||||
// }
|
||||
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
@@ -72,9 +73,6 @@ export class ProductService {
|
||||
.leftJoin('sub_categories.category', 'category')
|
||||
.leftJoin('product.supplier', 'supplier')
|
||||
.where('supplier.status = :status', { status: true })
|
||||
// .where(`product.supplier_id = :supplier_id`, {
|
||||
// supplier_id: In(supplier),
|
||||
// })
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
@@ -106,15 +104,9 @@ export class ProductService {
|
||||
});
|
||||
}
|
||||
|
||||
// if (categories != 'null' && categories) {
|
||||
// baseQuery.andWhere('sub_categories.category_id = :id', {
|
||||
// id: categories,
|
||||
// });
|
||||
// }
|
||||
|
||||
const data = await baseQuery
|
||||
.offset(page * 10)
|
||||
.limit(10)
|
||||
.offset(page * (pageSize || 10))
|
||||
.limit(pageSize || 10)
|
||||
.getRawMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
@@ -156,7 +148,7 @@ export class ProductService {
|
||||
};
|
||||
}
|
||||
|
||||
async findAllBySubCategories(page, subCategories, supplier) {
|
||||
async findAllBySubCategories(page, subCategories, supplier, pageSize?) {
|
||||
if (supplier != 'null' && !supplier) {
|
||||
supplier = (await this.supplierService.findByActive()).id;
|
||||
}
|
||||
@@ -184,8 +176,8 @@ export class ProductService {
|
||||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.skip(page * (pageSize || 10))
|
||||
.take(pageSize || 10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
Reference in New Issue
Block a user