You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
718 B
18 lines
718 B
import { Controller, Get, Post, Body, Patch, Param, Delete } from "@nestjs/common"; |
|
import { CartService } from "./cart.service"; |
|
import { Cart } from "./entities/cart.entity"; |
|
|
|
@Controller("cart") |
|
export class CartController { |
|
constructor(private readonly cartService: CartService) {} |
|
@Post() |
|
async addToCart(@Body() body: { userId: number; productId: number; quantity: number }): Promise<{ message: string; cartItem: Cart }> { |
|
const { userId, productId, quantity } = body; |
|
const result = await this.cartService.addToCart(userId, productId, quantity); |
|
return result; |
|
} |
|
@Get(':userId') |
|
async getUserCart(@Param('userId') userId: number) { |
|
return this.cartService.getUserCart(userId); |
|
} |
|
}
|
|
|