fix: product

This commit is contained in:
ilham 2021-12-16 23:54:51 +07:00
parent 2e04cd4ee1
commit dbf19eb77a
3 changed files with 38 additions and 6 deletions

View File

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

View File

@ -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',
};

View File

@ -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')