foods and ctegory

This commit is contained in:
2025-11-22 14:36:07 +03:30
parent 7a53f0fa1b
commit ee723c1c55
4 changed files with 42 additions and 1 deletions
@@ -0,0 +1,17 @@
import { Controller, Get, Param } from '@nestjs/common';
import { CategoryService } from '../providers/category.service';
import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger';
@ApiTags('categories')
@Controller('categories')
export class PublicCategoryController {
constructor(private readonly categoryService: CategoryService) {}
@Get('restaurant/:restId')
@ApiOperation({ summary: 'Get all categories by restaurant id' })
@ApiParam({ name: 'restId', required: true, description: 'Restaurant ID' })
@ApiOkResponse({ description: 'List of all categories for the restaurant' })
findAllByRestaurant(@Param('restId') restId: string) {
return this.categoryService.findAll({ restId });
}
}
@@ -0,0 +1,18 @@
import { Controller, Get, Param } from '@nestjs/common';
import { FoodService } from '../providers/food.service';
import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger';
@ApiTags('foods')
@Controller('foods')
export class PublicFoodController {
constructor(private readonly foodService: FoodService) {}
@Get('restaurant/:restId')
@ApiOperation({ summary: 'Get all foods by restaurant id' })
@ApiParam({ name: 'restId', required: true, description: 'Restaurant ID' })
@ApiOkResponse({ description: 'List of all foods for the restaurant' })
findAllByRestaurant(@Param('restId') restId: string) {
return this.foodService.findAllByRestaurant(restId);
}
}
+3 -1
View File
@@ -1,7 +1,9 @@
import { Module } from '@nestjs/common';
import { FoodService } from './providers/food.service';
import { FoodController } from './controllers/food.controller';
import { PublicFoodController } from './controllers/public-food.controller';
import { CategoryController } from './controllers/category.controller';
import { PublicCategoryController } from './controllers/public-category.controller';
import { CategoryService } from './providers/category.service';
import { FoodRepository } from './repositories/food.repository';
import { CategoryRepository } from './repositories/category.repository';
@@ -14,7 +16,7 @@ import { JwtModule } from '@nestjs/jwt';
@Module({
imports: [MikroOrmModule.forFeature([Food, Category]), RestaurantsModule, AuthModule, JwtModule],
controllers: [FoodController, CategoryController],
controllers: [FoodController, PublicFoodController, CategoryController, PublicCategoryController],
providers: [FoodService, CategoryService, FoodRepository, CategoryRepository],
exports: [FoodRepository, CategoryRepository],
})
@@ -70,6 +70,10 @@ export class FoodService {
return this.foodRepository.findAllPaginated(restId, dto);
}
async findAllByRestaurant(restId: string): Promise<Food[]> {
return this.foodRepository.find({ restaurant: { id: restId } });
}
findOne(id: string) {
return this.foodRepository.findOne({ id }, { populate: ['categories'] });
}