product module
This commit is contained in:
@@ -5,7 +5,7 @@ import { ApplyCouponDto } from '../dto/apply-coupon.dto';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiBody, ApiParam, ApiHeader } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '../../../auth/guards/auth.guard';
|
||||
import { UserId } from 'src/common/decorators/user-id.decorator';
|
||||
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
||||
import { ShopId } from 'src/common/decorators/rest-id.decorator';
|
||||
import { SetAllCartParmsDto } from '../dto/set-all-cart-params.dto';
|
||||
import { API_HEADER_SLUG } from 'src/common/constants/index';
|
||||
|
||||
@@ -14,12 +14,12 @@ import { API_HEADER_SLUG } from 'src/common/constants/index';
|
||||
@ApiTags('cart')
|
||||
@Controller('public/cart')
|
||||
export class CartController {
|
||||
constructor(private readonly cartService: CartService) {}
|
||||
constructor(private readonly cartService: CartService) { }
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get cart for current user and shop' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
async findOne(@UserId() userId: string, @RestId() restaurantId: string) {
|
||||
async findOne(@UserId() userId: string, @ShopId() restaurantId: string) {
|
||||
return this.cartService.getOrCreateCart(userId, restaurantId);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export class CartController {
|
||||
@ApiOperation({ summary: 'Increment item quantity in cart by 1' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'foodId', description: 'Product ID to increment in cart' })
|
||||
async incrementItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
async incrementItem(@UserId() userId: string, @ShopId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
return this.cartService.incrementItem(userId, restaurantId, foodId, 1);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export class CartController {
|
||||
@ApiOperation({ summary: 'Decrement item quantity in cart by 1 (removes item if quantity reaches 0)' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'foodId', description: 'Product ID to decrement in cart' })
|
||||
async decrementItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
async decrementItem(@UserId() userId: string, @ShopId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
return this.cartService.decrementItem(userId, restaurantId, foodId);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ export class CartController {
|
||||
@ApiBody({ type: BulkAddItemsToCartDto })
|
||||
bulkAddItems(
|
||||
@UserId() userId: string,
|
||||
@RestId() restaurantId: string,
|
||||
@ShopId() restaurantId: string,
|
||||
@Body() bulkAddItemsDto: BulkAddItemsToCartDto,
|
||||
) {
|
||||
return this.cartService.bulkAddItems(userId, restaurantId, bulkAddItemsDto);
|
||||
@@ -55,14 +55,14 @@ export class CartController {
|
||||
@ApiOperation({ summary: 'Remove item from cart' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiParam({ name: 'foodId', description: 'Product ID in the cart' })
|
||||
async removeItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
async removeItem(@UserId() userId: string, @ShopId() restaurantId: string, @Param('foodId') foodId: string) {
|
||||
return this.cartService.removeItem(userId, restaurantId, foodId);
|
||||
}
|
||||
|
||||
@Delete()
|
||||
@ApiOperation({ summary: 'Clear entire cart' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
async clearCart(@UserId() userId: string, @RestId() restaurantId: string) {
|
||||
async clearCart(@UserId() userId: string, @ShopId() restaurantId: string) {
|
||||
return this.cartService.clearCart(userId, restaurantId);
|
||||
}
|
||||
|
||||
@@ -70,14 +70,14 @@ export class CartController {
|
||||
@ApiOperation({ summary: 'Apply coupon to cart' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBody({ type: ApplyCouponDto })
|
||||
async applyCoupon(@UserId() userId: string, @RestId() restaurantId: string, @Body() applyCouponDto: ApplyCouponDto) {
|
||||
async applyCoupon(@UserId() userId: string, @ShopId() restaurantId: string, @Body() applyCouponDto: ApplyCouponDto) {
|
||||
return this.cartService.applyCoupon(userId, restaurantId, applyCouponDto);
|
||||
}
|
||||
|
||||
@Delete('coupon')
|
||||
@ApiOperation({ summary: 'Remove coupon from cart' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
async removeCoupon(@UserId() userId: string, @RestId() restaurantId: string) {
|
||||
async removeCoupon(@UserId() userId: string, @ShopId() restaurantId: string) {
|
||||
return this.cartService.removeCoupon(userId, restaurantId);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export class CartController {
|
||||
@ApiOperation({ summary: 'Set all cart params' })
|
||||
@ApiHeader(API_HEADER_SLUG)
|
||||
@ApiBody({ type: SetAllCartParmsDto })
|
||||
setAllCartParams(@UserId() userId: string, @RestId() restaurantId: string, @Body() dto: SetAllCartParmsDto) {
|
||||
setAllCartParams(@UserId() userId: string, @ShopId() restaurantId: string, @Body() dto: SetAllCartParmsDto) {
|
||||
return this.cartService.setAllCartParams(userId, restaurantId, dto);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user