foods and ctegory
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'] });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user