|
|
|
@ -10,21 +10,21 @@ import { Invoice } from "src/invoice/entities/invoice.entity"; |
|
|
|
|
export class CartController { |
|
|
|
|
constructor(private readonly cartService: CartService) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//create and a item to cart by user
|
|
|
|
|
@UseGuards(JwtAuthGuard) |
|
|
|
|
@Post() |
|
|
|
|
async createAndAddItemToCart(@Body() addToCartDto: AddToCartDto, @Request() req: any): Promise<{ message: string; cartItem: Cart }> { |
|
|
|
|
const userId = req.user.id; |
|
|
|
|
return this.cartService.createAndAddItemToCart({ ...addToCartDto, userId }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//get user cart items
|
|
|
|
|
@UseGuards(JwtAuthGuard) |
|
|
|
|
@Get() |
|
|
|
|
async getUserOpenCart(@Request() req: any): Promise<{ cartItems: Cart[]; totalPrice: number }> { |
|
|
|
|
const userId = req.user.id; |
|
|
|
|
return this.cartService.getUserOpenCart(userId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//edit quantity an item in cart by user
|
|
|
|
|
@UseGuards(JwtAuthGuard) |
|
|
|
|
@Patch(":productId") |
|
|
|
|
async updateCart(@Param("productId") productId: number, @Body() updateCartDto: UpdateCartDto, @Request() req: any): Promise<{ message: string; updatedCart: Cart }> { |
|
|
|
@ -35,14 +35,21 @@ export class CartController { |
|
|
|
|
updatedCart, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//delete an item from cart by user
|
|
|
|
|
@UseGuards(JwtAuthGuard) |
|
|
|
|
@Delete(":productId") |
|
|
|
|
async removeFromCart(@Param("productId") productId: number, @Request() req: any) { |
|
|
|
|
const userId = req.user.id; |
|
|
|
|
return await this.cartService.removeFromCart(userId, productId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//clear whole cart by user
|
|
|
|
|
@UseGuards(JwtAuthGuard) |
|
|
|
|
@Get("clear-cart") |
|
|
|
|
async clearCart(@Request() req: any) { |
|
|
|
|
const userId = req.user.id; |
|
|
|
|
return await this.cartService.clearCart(userId); |
|
|
|
|
} |
|
|
|
|
//get checkout process
|
|
|
|
|
@UseGuards(JwtAuthGuard) |
|
|
|
|
@Get("checkout") |
|
|
|
|
async processOrder(@Request() req: any): Promise<{ message: string; invoice: Invoice }> { |
|
|
|
|