add: get product by categories

This commit is contained in:
ilham
2021-12-10 00:14:05 +07:00
parent a057088a93
commit 09c84f2cf5
4 changed files with 302 additions and 165 deletions

View File

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

View File

@@ -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 });