product module
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { FoodService } from '../providers/product.service';
|
||||
import { CreateFoodDto } from '../dto/create-product.dto';
|
||||
import { ProductService } from '../providers/product.service';
|
||||
import { CreateProductDto } from '../dto/create-product.dto';
|
||||
import { UpdateFoodDto } from '../dto/update-product.dto';
|
||||
import { FindFoodsDto } from ../../../products.dto';
|
||||
import { FindProductsDto } from '../dto/find-products.dto';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
ApiHeader,
|
||||
} from '@nestjs/swagger';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { RestId, UserId } from 'src/common/decorators';
|
||||
import { ShopId, UserId } from 'src/common/decorators';
|
||||
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
||||
import { OptionalAuthGuard } from 'src/modules/auth/guards/optinalAuth.guard';
|
||||
import { API_HEADER_SLUG } from 'src/common/constants';
|
||||
@@ -23,35 +23,34 @@ import { Permissions } from 'src/common/decorators/permissions.decorator';
|
||||
@ApiTags('products')
|
||||
@Controller()
|
||||
export class FoodController {
|
||||
constructor(private readonly foodsService: FoodService) { }
|
||||
constructor(private readonly productService: ProductService) { }
|
||||
|
||||
@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.foodsService.findByWeekDateAndMealType(slug);
|
||||
return this.productService.findByShop(slug);
|
||||
}
|
||||
|
||||
@Get('public/products/:foodId')
|
||||
@Get('public/products/:id')
|
||||
@UseGuards(OptionalAuthGuard)
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get a product by id' })
|
||||
@ApiParam({ name: 'foodId', required: true })
|
||||
findPublicFoodById(@Param('foodId') foodId: string, @UserId() userId?: string): Promise<any> {
|
||||
const a = this.foodsService.findPublicById(foodId, userId);
|
||||
findPublicFoodById(@Param('id') productId: string, @UserId() userId?: string): Promise<any> {
|
||||
const a = this.productService.findPublicById(productId, userId);
|
||||
return a;
|
||||
}
|
||||
|
||||
@Post('public/products/favorite/:foodId')
|
||||
@Post('public/products/:id/favorite')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'toggle a product as favorite' })
|
||||
@ApiParam({ name: 'foodId', required: true })
|
||||
setAsFavorute(@Param('foodId') foodId: string, @UserId() userId: string) {
|
||||
return this.foodsService.toggleFavorite(userId, foodId);
|
||||
@ApiParam({ name: 'productId', required: true })
|
||||
setAsFavorute(@Param('productId') productId: string, @UserId() userId: string) {
|
||||
return this.productService.toggleFavorite(userId, productId);
|
||||
}
|
||||
|
||||
@Get('public/products/favorite')
|
||||
@@ -59,8 +58,8 @@ export class FoodController {
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'get my favorites' })
|
||||
getMyFavorites(@UserId() userId: string, @RestId() restId: string) {
|
||||
return this.foodsService.getMyFavorites(userId, restId);
|
||||
getMyFavorites(@UserId() userId: string, @ShopId() restId: string) {
|
||||
return this.productService.getMyFavorites(userId, restId);
|
||||
}
|
||||
|
||||
/* ---------------------------------- Admin ---------------------------------- */
|
||||
@@ -69,9 +68,8 @@ export class FoodController {
|
||||
@Permissions(Permission.MANAGE_FOODS)
|
||||
@Post('admin/products')
|
||||
@ApiOperation({ summary: 'Create a new product' })
|
||||
@ApiBody({ type: CreateFoodDto })
|
||||
create(@Body() createFoodDto: CreateFoodDto, @RestId() restId: string) {
|
||||
return this.foodsService.create(restId, createFoodDto);
|
||||
create(@Body() createFoodDto: CreateProductDto, @ShopId() restId: string) {
|
||||
return this.productService.create(restId, createFoodDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@@ -86,8 +84,8 @@ export class FoodController {
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
@ApiQuery({ name: 'categoryId', required: false, type: String })
|
||||
@ApiQuery({ name: 'isActive', required: false, type: Boolean })
|
||||
async findAll(@Query() dto: FindFoodsDto, @RestId() restId: string) {
|
||||
const result = await this.foodsService.findAll(restId, dto);
|
||||
async findAll(@Query() dto: FindProductsDto, @ShopId() restId: string) {
|
||||
const result = await this.productService.findAll(restId, dto);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -97,8 +95,8 @@ export class FoodController {
|
||||
@Get('admin/products/:id')
|
||||
@ApiOperation({ summary: 'Get a product by id' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
findById(@Param('id') id: string, @RestId() restId: string) {
|
||||
return this.foodsService.findAdminById(restId, id);
|
||||
findById(@Param('id') id: string, @ShopId() restId: string) {
|
||||
return this.productService.findAdminById(restId, id);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@@ -108,16 +106,15 @@ export class FoodController {
|
||||
@ApiOperation({ summary: 'Update a product' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: UpdateFoodDto })
|
||||
update(@Param('id') id: string, @Body() updateFoodDto: UpdateFoodDto, @RestId() restId: string) {
|
||||
return this.foodsService.update(restId, id, updateFoodDto);
|
||||
update(@Param('id') id: string, @Body() updateFoodDto: UpdateFoodDto, @ShopId() restId: string) {
|
||||
return this.productService.update(restId, id, updateFoodDto);
|
||||
}
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_FOODS)
|
||||
@Delete('admin/products/:id')
|
||||
@ApiOperation({ summary: 'Delete (soft) a product' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
remove(@Param('id') id: string, @RestId() restId: string) {
|
||||
return this.foodsService.remove(restId, id);
|
||||
remove(@Param('id') id: string, @ShopId() restId: string) {
|
||||
return this.productService.remove(restId, id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user