food==. product
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { productService } from '../providers/product.service';
|
||||
import { CreateproductDto } from '../dto/create-product.dto';
|
||||
import { UpdateproductDto } from '../dto/update-product.dto';
|
||||
import { FindproductsDto } from '../dto/find-products.dto';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
ApiCreatedResponse,
|
||||
ApiOkResponse,
|
||||
ApiNotFoundResponse,
|
||||
ApiQuery,
|
||||
ApiBody,
|
||||
ApiParam,
|
||||
ApiBearerAuth,
|
||||
ApiHeader,
|
||||
} from '@nestjs/swagger';
|
||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||
import { RestId, 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';
|
||||
import { Permission } from 'src/common/enums/permission.enum';
|
||||
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
||||
|
||||
@ApiTags('products')
|
||||
@Controller()
|
||||
export class productController {
|
||||
constructor(private readonly productsService: productService) { }
|
||||
|
||||
@Get('public/products/restaurant/:slug')
|
||||
@ApiOperation({ summary: 'Get all products by restaurant slug' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'slug', required: true, description: 'Restaurant Slug' })
|
||||
findAllByRestaurant(@Param('slug') slug: string) {
|
||||
return this.productsService.findByWeekDateAndMealType(slug);
|
||||
}
|
||||
|
||||
@Get('public/products/:productId')
|
||||
@UseGuards(OptionalAuthGuard)
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get a product by id' })
|
||||
@ApiParam({ name: 'productId', required: true })
|
||||
findPublicproductById(@Param('productId') productId: string, @UserId() userId?: string): Promise<any> {
|
||||
const a = this.productsService.findPublicById(productId, userId);
|
||||
return a;
|
||||
}
|
||||
|
||||
@Post('public/products/favorite/:productId')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'toggle a product as favorite' })
|
||||
@ApiParam({ name: 'productId', required: true })
|
||||
setAsFavorute(@Param('productId') productId: string, @UserId() userId: string) {
|
||||
return this.productsService.toggleFavorite(userId, productId);
|
||||
}
|
||||
|
||||
@Get('public/products/favorite')
|
||||
@UseGuards(AuthGuard)
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'get my favorites' })
|
||||
getMyFavorites(@UserId() userId: string, @RestId() restId: string) {
|
||||
return this.productsService.getMyFavorites(userId, restId);
|
||||
}
|
||||
|
||||
/* ---------------------------------- Admin ---------------------------------- */
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@Post('admin/products')
|
||||
@ApiOperation({ summary: 'Create a new product' })
|
||||
@ApiBody({ type: CreateproductDto })
|
||||
create(@Body() createproductDto: CreateproductDto, @RestId() restId: string) {
|
||||
return this.productsService.create(restId, createproductDto);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@Get('admin/products')
|
||||
@ApiOperation({ summary: 'Get a paginated list of products' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'search', required: false, type: String })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@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: FindproductsDto, @RestId() restId: string) {
|
||||
const result = await this.productsService.findAll(restId, dto);
|
||||
return result;
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@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.productsService.findAdminById(restId, id);
|
||||
}
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@Patch('admin/products/:id')
|
||||
@ApiOperation({ summary: 'Update a product' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: UpdateproductDto })
|
||||
update(@Param('id') id: string, @Body() updateproductDto: UpdateproductDto, @RestId() restId: string) {
|
||||
return this.productsService.update(restId, id, updateproductDto);
|
||||
}
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@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.productsService.remove(restId, id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user