|
|
|
@ -59,15 +59,14 @@ export class CartService { |
|
|
|
|
cartItem: cart, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get user's cart
|
|
|
|
|
async getUserCart(userId: number): Promise<{ cartItems: Cart[]; totalPrice: number }> { |
|
|
|
|
async getUserOpenCart(userId: number): Promise<{ cartItems: Cart[]; totalPrice: number }> { |
|
|
|
|
if (!userId) { |
|
|
|
|
throw new HttpException("User ID is required.", HttpStatus.BAD_REQUEST); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const cartItems = await this.cartModel.findAll({ |
|
|
|
|
where: { userId }, |
|
|
|
|
where: { userId,status:"open" }, |
|
|
|
|
include: [ |
|
|
|
|
{ |
|
|
|
|
model: Product, |
|
|
|
@ -120,7 +119,6 @@ export class CartService { |
|
|
|
|
async processOrder(userId: number, totalAmount: number): Promise<{ message: string; invoice: Invoice }> { |
|
|
|
|
try { |
|
|
|
|
const carts = await this.cartModel.findAll({ where: { userId, status: "open" } }); |
|
|
|
|
|
|
|
|
|
if (!carts || carts.length === 0) { |
|
|
|
|
throw new HttpException("No open carts found for this user.", HttpStatus.NOT_FOUND); |
|
|
|
|
} |
|
|
|
|