Refactor checkout route structure for better clarity and performance

master
nicekid1 2 months ago
parent 3110dc9645
commit 188723aee7
  1. 13
      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) {

Loading…
Cancel
Save