|
|
@ -23,37 +23,30 @@ export class InvoiceService { |
|
|
|
throw new HttpException("Cart is empty", HttpStatus.BAD_REQUEST); |
|
|
|
throw new HttpException("Cart is empty", HttpStatus.BAD_REQUEST); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const products = userCartItems.cartItems.map(item => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
productId: item.productId, |
|
|
|
|
|
|
|
quantity: item.quantity, |
|
|
|
|
|
|
|
price: item.productPrice, |
|
|
|
|
|
|
|
productName: item.productName, |
|
|
|
|
|
|
|
totalPrice: item.totalPrice, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ذخیره کردن فاکتورهای هر محصول و بازگشت آرایه فاکتورها
|
|
|
|
|
|
|
|
const invoices: Invoice[] = [];
|
|
|
|
const invoices: Invoice[] = [];
|
|
|
|
for (const product of products) { |
|
|
|
|
|
|
|
|
|
|
|
for (const cartItem of userCartItems.cartItems) { |
|
|
|
const invoice = await this.invoiceModel.create({ |
|
|
|
const invoice = await this.invoiceModel.create({ |
|
|
|
userId, |
|
|
|
userId, |
|
|
|
firstName: user.firstName, |
|
|
|
firstName: user.firstName, |
|
|
|
lastName: user.lastName, |
|
|
|
lastName: user.lastName, |
|
|
|
phoneNumber: user.phoneNumber, |
|
|
|
phoneNumber: user.phoneNumber, |
|
|
|
email: user.email, |
|
|
|
email: user.email, |
|
|
|
totalAmount: userCartItems.totalPrice, |
|
|
|
totalPaymentAmount: userCartItems.totalPrice, |
|
|
|
productId: product.productId, |
|
|
|
productId: cartItem.productId, |
|
|
|
quantity: product.quantity, |
|
|
|
quantity: cartItem.quantity, |
|
|
|
price: product.price, |
|
|
|
price: cartItem.productPrice, |
|
|
|
productName: product.productName, |
|
|
|
totalPrice:(cartItem.quantity*cartItem.productPrice), |
|
|
|
|
|
|
|
productName: cartItem.productName, |
|
|
|
}); |
|
|
|
}); |
|
|
|
invoices.push(invoice); // ذخیره فاکتور برای هر محصول
|
|
|
|
|
|
|
|
|
|
|
|
invoices.push(invoice); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return invoices; |
|
|
|
return invoices; // بازگرداندن آرایهای از فاکتورها
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async getInvoicesByUser(userId: number): Promise<Invoice[]> { |
|
|
|
async getInvoicesByUser(userId: number): Promise<Invoice[]> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!userId) { |
|
|
|
if (!userId) { |
|
|
|