add: get product by categories
This commit is contained in:
@@ -78,6 +78,21 @@ export class ProductController {
|
||||
};
|
||||
}
|
||||
|
||||
@Get('by-categories')
|
||||
async findByCategories(
|
||||
@Query('page') page: number,
|
||||
@Query('categories') categories: string,
|
||||
) {
|
||||
const [data, count] = await this.productService.findAll(page);
|
||||
|
||||
return {
|
||||
data,
|
||||
count,
|
||||
statusCode: HttpStatus.OK,
|
||||
message: 'success',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('categories')
|
||||
async findAllCategories(@Query('page') page: number) {
|
||||
const [data, count] = await this.productCategoriesService.findAll(page);
|
||||
|
||||
@@ -53,6 +53,19 @@ export class ProductService {
|
||||
});
|
||||
}
|
||||
|
||||
findAllByCategories(page, categories) {
|
||||
return this.productRepository.findAndCount({
|
||||
where: {
|
||||
subCategories: categories,
|
||||
},
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
order: {
|
||||
version: 'DESC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(code: string) {
|
||||
try {
|
||||
return await this.productRepository.findOneOrFail({ code: code });
|
||||
|
||||
Reference in New Issue
Block a user