category
This commit is contained in:
@@ -28,9 +28,8 @@ export class FoodController {
|
||||
@Get('public/products/shop/:slug')
|
||||
@ApiOperation({ summary: 'Get all products by shop slug' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'slug', required: true, description: 'Shop Slug' })
|
||||
findAllByRestaurant(@Param('slug') slug: string) {
|
||||
return this.productService.findByShop(slug);
|
||||
findAllByRestaurant(@Param('slug') slug: string, @Query('categoryId') categoryId?: string) {
|
||||
return this.productService.findByShop(slug, categoryId);
|
||||
}
|
||||
|
||||
@Get('public/products/:id')
|
||||
|
||||
@@ -47,14 +47,13 @@ export class CategoryService {
|
||||
async findAllByShopSlug(shopSlug: string): Promise<Category[]> {
|
||||
return this.categoryRepository.find(
|
||||
{ shop: { slug: shopSlug }, isActive: true, parent: null },
|
||||
{ orderBy: { order: 'ASC' }, populate: ['children','parent'] });
|
||||
{ orderBy: { order: 'ASC' }, populate: ['children', 'parent'] });
|
||||
}
|
||||
|
||||
async findAllByShopId(shopId: string): Promise<Category[]> {
|
||||
console.log('findAllByShopId',shopId)
|
||||
return this.categoryRepository.find(
|
||||
{ shop: { id: shopId } },
|
||||
{ orderBy: { createdAt: 'DESC' }, populate: ['children','parent'] });
|
||||
{ shop: { id: shopId }, parent: null },
|
||||
{ orderBy: { createdAt: 'DESC' }, populate: ['children', 'parent'] });
|
||||
}
|
||||
|
||||
async findOne(shopId: string, categoryId: string): Promise<Category> {
|
||||
@@ -96,7 +95,7 @@ export class CategoryService {
|
||||
}
|
||||
|
||||
async findOrFail(categoryId: string) {
|
||||
const category = await this.categoryRepository.findOne({ id: categoryId },{populate:['parent','children']});
|
||||
const category = await this.categoryRepository.findOne({ id: categoryId }, { populate: ['parent', 'children'] });
|
||||
if (!category) throw new NotFoundException(CategoryMessage.NOT_FOUND);
|
||||
return category
|
||||
}
|
||||
|
||||
@@ -100,11 +100,19 @@ export class ProductService {
|
||||
}
|
||||
|
||||
|
||||
async findByShop(slug: string): Promise<Product[]> {
|
||||
async findByShop(slug: string, categoryId?: string): Promise<Product[]> {
|
||||
const shop = await this.shopService.findBySlug(slug);
|
||||
|
||||
const where: { shop: { id: string }; isActive: boolean; category?: { id: string } } = {
|
||||
shop: { id: shop.id },
|
||||
isActive: true,
|
||||
};
|
||||
if (categoryId) {
|
||||
where.category = { id: categoryId };
|
||||
}
|
||||
|
||||
return this.productRepository.find(
|
||||
{ shop: { id: shop.id }, isActive: true },
|
||||
where,
|
||||
{ populate: ['category', 'variants'], orderBy: { order: 'asc' } }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user