fix: product
This commit is contained in:
parent
2e04cd4ee1
commit
dbf19eb77a
|
@ -44,10 +44,40 @@ export class ProductSubCategoriesService {
|
|||
);
|
||||
}
|
||||
|
||||
findAll(page) {
|
||||
async findAll(page, category) {
|
||||
const baseQuery = this.productSubCategoriesRepository
|
||||
.createQueryBuilder('product_sub_categories')
|
||||
.leftJoinAndSelect(
|
||||
'product_sub_categories.category',
|
||||
'category',
|
||||
);
|
||||
|
||||
if (category != 'null') {
|
||||
baseQuery.where({
|
||||
category: category,
|
||||
});
|
||||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
return {
|
||||
data,
|
||||
count: totalData,
|
||||
};
|
||||
}
|
||||
|
||||
findAllByCategories(page, category) {
|
||||
return this.productSubCategoriesRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
where: {
|
||||
category: category,
|
||||
},
|
||||
relations: ['category'],
|
||||
order: {
|
||||
version: 'DESC',
|
||||
|
|
|
@ -98,7 +98,7 @@ export class ProductController {
|
|||
@Get('by-categories-all')
|
||||
async findByCategoriesAll(
|
||||
@Query('page') page: number,
|
||||
@Query('categories') categories: string,
|
||||
@Query('sub-categories') categories: string,
|
||||
@Query('supplier') supplier: string,
|
||||
) {
|
||||
const data = await this.productService.findAllBySubCategories(
|
||||
|
@ -148,12 +148,11 @@ export class ProductController {
|
|||
}
|
||||
|
||||
@Get('sub-categories')
|
||||
async findAllSubCategories(@Query('page') page: number) {
|
||||
const [data, count] = await this.productSubCategoriesService.findAll(page);
|
||||
async findAllSubCategories(@Query('page') page: number,@Query('category') category: string) {
|
||||
const data = await this.productSubCategoriesService.findAll(page, category);
|
||||
|
||||
return {
|
||||
data,
|
||||
count,
|
||||
...data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
|
|
|
@ -95,6 +95,9 @@ export class ProductService {
|
|||
}
|
||||
|
||||
async findAllBySubCategories(page, subCategories, supplier) {
|
||||
if (!supplier) {
|
||||
supplier = await this.supplierService.findByActive();
|
||||
}
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
|
|
Loading…
Reference in New Issue
Block a user