foods
This commit is contained in:
@@ -18,14 +18,22 @@ import {
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { RestId } from 'src/common/decorators';
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiTags('admin/foods')
|
||||
@Controller('admin/foods')
|
||||
@ApiTags('foods')
|
||||
@Controller()
|
||||
export class FoodController {
|
||||
constructor(private readonly foodsService: FoodService) {}
|
||||
|
||||
@Post()
|
||||
@Get('public/foods/restaurant/:slug')
|
||||
@ApiOperation({ summary: 'Get all foods by restaurant slug' })
|
||||
@ApiParam({ name: 'slug', required: true, description: 'Restaurant Slug' })
|
||||
@ApiOkResponse({ description: 'List of all foods for the restaurant' })
|
||||
findAllByRestaurant(@Param('slug') slug: string) {
|
||||
return this.foodsService.findAllByRestaurant(slug);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Post('admin/foods')
|
||||
@ApiOperation({ summary: 'Create a new food' })
|
||||
@ApiCreatedResponse({ description: 'The food has been successfully created.', type: CreateFoodDto })
|
||||
@ApiBody({ type: CreateFoodDto })
|
||||
@@ -33,7 +41,9 @@ export class FoodController {
|
||||
return this.foodsService.create(restId, createFoodDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get('admin/foods')
|
||||
@ApiOperation({ summary: 'Get a paginated list of foods' })
|
||||
@ApiOkResponse({ description: 'Paginated list of foods' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@@ -47,6 +57,8 @@ export class FoodController {
|
||||
return this.foodsService.findAll(restId, dto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a food by id' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@@ -56,6 +68,8 @@ export class FoodController {
|
||||
return this.foodsService.findOne(id);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Patch(':id')
|
||||
@ApiOperation({ summary: 'Update a food' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@@ -64,7 +78,8 @@ export class FoodController {
|
||||
update(@Param('id') id: string, @Body() updateFoodDto: UpdateFoodDto) {
|
||||
return this.foodsService.update(id, updateFoodDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete (soft) a food' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { FoodService } from '../providers/food.service';
|
||||
import { ApiTags, ApiOperation, ApiOkResponse, ApiParam } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('public/foods')
|
||||
@Controller('public/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,6 @@
|
||||
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';
|
||||
@@ -16,7 +15,7 @@ import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
@Module({
|
||||
imports: [MikroOrmModule.forFeature([Food, Category]), RestaurantsModule, AuthModule, JwtModule],
|
||||
controllers: [FoodController, PublicFoodController, CategoryController, PublicCategoryController],
|
||||
controllers: [FoodController, CategoryController, PublicCategoryController],
|
||||
providers: [FoodService, CategoryService, FoodRepository, CategoryRepository],
|
||||
exports: [FoodRepository, CategoryRepository],
|
||||
})
|
||||
|
||||
@@ -70,8 +70,12 @@ export class FoodService {
|
||||
return this.foodRepository.findAllPaginated(restId, dto);
|
||||
}
|
||||
|
||||
async findAllByRestaurant(restId: string): Promise<Food[]> {
|
||||
return this.foodRepository.find({ restaurant: { id: restId } });
|
||||
async findAllByRestaurant(slug: string): Promise<Food[]> {
|
||||
const restaurant = await this.restRepository.findOne({ slug });
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
return this.foodRepository.find({ restaurant: { slug } });
|
||||
}
|
||||
|
||||
findOne(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user