add: get product all
This commit is contained in:
parent
8df907287a
commit
3c8b018937
|
@ -69,13 +69,22 @@ export class ProductController {
|
|||
};
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(@Query('page') page: number) {
|
||||
const [data, count] = await this.productService.findAll(page);
|
||||
@Get('get-all')
|
||||
async findAll(
|
||||
@Query('page') page: number,
|
||||
@Query('sub-category') subcategory: string,
|
||||
@Query('category') category: string,
|
||||
@Query('supplier') supplier: string,
|
||||
) {
|
||||
const data = await this.productService.findAll(
|
||||
page,
|
||||
supplier,
|
||||
category,
|
||||
subcategory,
|
||||
);
|
||||
|
||||
return {
|
||||
data,
|
||||
count,
|
||||
...data,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
|
@ -148,7 +157,10 @@ export class ProductController {
|
|||
}
|
||||
|
||||
@Get('sub-categories')
|
||||
async findAllSubCategories(@Query('page') page: number,@Query('category') category: string) {
|
||||
async findAllSubCategories(
|
||||
@Query('page') page: number,
|
||||
@Query('category') category: string,
|
||||
) {
|
||||
const data = await this.productSubCategoriesService.findAll(page, category);
|
||||
|
||||
return {
|
||||
|
|
|
@ -53,15 +53,47 @@ export class ProductService {
|
|||
return this.productRepository.findOneOrFail(result.identifiers[0].id);
|
||||
}
|
||||
|
||||
findAll(page) {
|
||||
return this.productRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
relations: ['sub_categories'],
|
||||
take: 10,
|
||||
order: {
|
||||
version: 'DESC',
|
||||
},
|
||||
});
|
||||
async findAll(page, supplier, categories, subCategories) {
|
||||
if (supplier != 'null' && !supplier) {
|
||||
supplier = (await this.supplierService.findByActive()).id;
|
||||
}
|
||||
const baseQuery = this.productRepository
|
||||
.createQueryBuilder('product')
|
||||
.leftJoin('product.sub_categories', 'sub_categories')
|
||||
.leftJoin('sub_categories.category', 'category')
|
||||
.where('product.supplier_id = :supplier_id', {
|
||||
supplier_id: supplier,
|
||||
})
|
||||
.leftJoinAndMapOne(
|
||||
'product.currentPrice',
|
||||
'product.priceHistory',
|
||||
'current_price',
|
||||
'current_price.partner_id is null',
|
||||
);
|
||||
|
||||
if (subCategories != 'null' && subCategories) {
|
||||
baseQuery.where('product.sub_categories_id = :id', {
|
||||
id: subCategories,
|
||||
});
|
||||
}
|
||||
|
||||
if (categories != 'null' && categories) {
|
||||
baseQuery.where('sub_categories.category_id = :id', {
|
||||
id: categories,
|
||||
});
|
||||
}
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * 10)
|
||||
.take(10)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
return {
|
||||
data,
|
||||
count: totalData,
|
||||
};
|
||||
}
|
||||
|
||||
async findAllByCategories(page, subCategories, supplier) {
|
||||
|
@ -113,7 +145,6 @@ export class ProductService {
|
|||
);
|
||||
|
||||
if (subCategories != 'null' && subCategories) {
|
||||
console.log(!subCategories,"testingan")
|
||||
baseQuery.where('product.sub_categories_id = :id', {
|
||||
id: subCategories,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user