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({ return this.productSubCategoriesRepository.findAndCount({
skip: page * 10, skip: page * 10,
take: 10, take: 10,
where: {
category: category,
},
relations: ['category'], relations: ['category'],
order: { order: {
version: 'DESC', version: 'DESC',

View File

@ -98,7 +98,7 @@ export class ProductController {
@Get('by-categories-all') @Get('by-categories-all')
async findByCategoriesAll( async findByCategoriesAll(
@Query('page') page: number, @Query('page') page: number,
@Query('categories') categories: string, @Query('sub-categories') categories: string,
@Query('supplier') supplier: string, @Query('supplier') supplier: string,
) { ) {
const data = await this.productService.findAllBySubCategories( const data = await this.productService.findAllBySubCategories(
@ -148,12 +148,11 @@ export class ProductController {
} }
@Get('sub-categories') @Get('sub-categories')
async findAllSubCategories(@Query('page') page: number) { async findAllSubCategories(@Query('page') page: number,@Query('category') category: string) {
const [data, count] = await this.productSubCategoriesService.findAll(page); const data = await this.productSubCategoriesService.findAll(page, category);
return { return {
data, ...data,
count,
statusCode: HttpStatus.OK, statusCode: HttpStatus.OK,
message: 'success', message: 'success',
}; };

View File

@ -95,6 +95,9 @@ export class ProductService {
} }
async findAllBySubCategories(page, subCategories, supplier) { async findAllBySubCategories(page, subCategories, supplier) {
if (!supplier) {
supplier = await this.supplierService.findByActive();
}
const baseQuery = this.productRepository const baseQuery = this.productRepository
.createQueryBuilder('product') .createQueryBuilder('product')
.leftJoin('product.sub_categories', 'sub_categories') .leftJoin('product.sub_categories', 'sub_categories')