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