Refactor checkout route structure for better clarity and performance

master
nicekid1 2 months ago
parent 3110dc9645
commit 188723aee7
  1. 11
      src/cart/cart.controller.ts

@ -46,13 +46,12 @@ export class CartController {
}; };
} }
@Post(":userId/checkout") @UseGuards(JwtAuthGuard)
async processOrder(@Param("userId") userId: number, @Body("totalAmount") totalAmount: number): Promise<{ message: string; invoice: Invoice }> { @Get("checkout")
if (!totalAmount || totalAmount <= 0) { async processOrder(@Request() req: any): Promise<{ message: string; invoice: Invoice }> {
throw new HttpException("Invalid total amount.", HttpStatus.BAD_REQUEST); const userId = req.user.id;
}
try { try {
const totalAmount = (await this.cartService.getUserCart(userId)).totalPrice
const result = await this.cartService.processOrder(userId, totalAmount); const result = await this.cartService.processOrder(userId, totalAmount);
return result; return result;
} catch (error) { } catch (error) {

Loading…
Cancel
Save