|
|
|
@ -36,7 +36,7 @@ export class CartService { |
|
|
|
|
const invoiceId = invoice.id; |
|
|
|
|
|
|
|
|
|
let cart = await this.cartModel.findOne({ where: { userId, productId, status: "open" } }); |
|
|
|
|
console.log(cart) |
|
|
|
|
console.log(cart); |
|
|
|
|
if (!cart) { |
|
|
|
|
cart = await this.cartModel.create({ |
|
|
|
|
userId, |
|
|
|
@ -95,6 +95,7 @@ export class CartService { |
|
|
|
|
|
|
|
|
|
cartItem.quantity = quantity; |
|
|
|
|
await cartItem.save(); |
|
|
|
|
await this.invoiceService.updateTotalPayment(userId); |
|
|
|
|
return cartItem; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -105,8 +106,8 @@ export class CartService { |
|
|
|
|
if (!cartItem) { |
|
|
|
|
throw new HttpException("Product not found in the cart.", HttpStatus.NOT_FOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await cartItem.destroy(); |
|
|
|
|
await this.invoiceService.updateTotalPayment(userId); |
|
|
|
|
return { message: "Item deleted from your cart successfully." }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -116,15 +117,13 @@ export class CartService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//order(clearCart disable)
|
|
|
|
|
async processOrder(userId: number, totalAmount: number): Promise<{ message: string; invoices: Invoice }> { |
|
|
|
|
async processOrder(userId: number, totalAmount: number): Promise<{ message: string; invoice: Invoice }> { |
|
|
|
|
try { |
|
|
|
|
const cart = await this.cartModel.findOne({ where: { userId } }); |
|
|
|
|
if (!cart) { |
|
|
|
|
throw new HttpException("Cart not found for this user.", HttpStatus.NOT_FOUND); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const cartId = cart.id; |
|
|
|
|
|
|
|
|
|
// Deducting credit from wallet
|
|
|
|
|
await this.walletService.processPayment(userId, totalAmount); |
|
|
|
|
|
|
|
|
@ -153,9 +152,8 @@ export class CartService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Create the invoices for all cart
|
|
|
|
|
const invoices = await this.invoiceService.createInvoiceFromCart(userId); |
|
|
|
|
|
|
|
|
|
return { message: "Order processed successfully", invoices }; |
|
|
|
|
const invoice = await this.invoiceModel.findOne({ where: { userId, status: "pending" } }); |
|
|
|
|
return { message: "Order processed successfully", invoice }; |
|
|
|
|
} catch (error) { |
|
|
|
|
console.log(error); |
|
|
|
|
if (error instanceof HttpException) { |
|
|
|
|