|
|
|
@ -76,4 +76,26 @@ export class CartService { |
|
|
|
|
throw new HttpException("An error occurred while retrieving the cart.", HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async removeFromCart(userId: number, productId: number): Promise<{ message: string }> { |
|
|
|
|
try { |
|
|
|
|
const cartItem = await this.cartModel.findOne({ where: { userId, productId } }); |
|
|
|
|
|
|
|
|
|
if (!cartItem) { |
|
|
|
|
throw new HttpException('Product not found in the cart.', HttpStatus.NOT_FOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await cartItem.destroy(); |
|
|
|
|
return { message: 'Item deleted from your cart successfully.' }; |
|
|
|
|
} catch (error) { |
|
|
|
|
if (error instanceof HttpException) { |
|
|
|
|
throw error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
throw new HttpException( |
|
|
|
|
'An error occurred while removing the product from the cart.', |
|
|
|
|
HttpStatus.INTERNAL_SERVER_ERROR, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|