diff --git a/src/cart/cart.controller.ts b/src/cart/cart.controller.ts index a8a09d5..2d123c4 100644 --- a/src/cart/cart.controller.ts +++ b/src/cart/cart.controller.ts @@ -45,14 +45,13 @@ export class CartController { message: "Product removed from cart successfully", }; } - - @Post(":userId/checkout") - async processOrder(@Param("userId") userId: number, @Body("totalAmount") totalAmount: number): Promise<{ message: string; invoice: Invoice }> { - if (!totalAmount || totalAmount <= 0) { - throw new HttpException("Invalid total amount.", HttpStatus.BAD_REQUEST); - } - + + @UseGuards(JwtAuthGuard) + @Get("checkout") + async processOrder(@Request() req: any): Promise<{ message: string; invoice: Invoice }> { + const userId = req.user.id; try { + const totalAmount = (await this.cartService.getUserCart(userId)).totalPrice const result = await this.cartService.processOrder(userId, totalAmount); return result; } catch (error) {