feat(checkout): define CreatePurchasePayload interface and update createPurchase method to use it
This commit is contained in:
@@ -5,7 +5,7 @@ import { startWith } from 'rxjs';
|
||||
|
||||
import { CartService } from '../../../../core/services/cart/cart.service';
|
||||
import { TenantService } from '../../../../core/services/tenant.service';
|
||||
import { CheckoutService } from '../../../../core/services/checkout.service';
|
||||
import { CheckoutService, CreatePurchasePayload } from '../../../../core/services/checkout.service';
|
||||
import { BankAccount } from '../../../../core/services/tenant.interface';
|
||||
import { CartItem } from '../../../../core/services/cart/cart.interface';
|
||||
import { CartComponent, CartItemMock } from '../../../../shared/components/cart/cart.component';
|
||||
@@ -125,15 +125,18 @@ export class CheckoutPageComponent {
|
||||
this.isCreatingPurchase.set(true);
|
||||
|
||||
try {
|
||||
const cartItems = this.cartService.cart()?.items || [];
|
||||
const cart = this.cartService.cart();
|
||||
if (!cart?.id) {
|
||||
throw new Error('No hay un carrito activo para finalizar la compra.');
|
||||
}
|
||||
|
||||
const formValue = this.form.getRawValue();
|
||||
const payload = {
|
||||
...formValue,
|
||||
const payload: CreatePurchasePayload = {
|
||||
cart_id: cart.id,
|
||||
dni: formValue.dni,
|
||||
telefono: formValue.telefono,
|
||||
email: formValue.email,
|
||||
nombre_apellido: formValue.nombre,
|
||||
items: cartItems.map((item) => ({
|
||||
producto_variante_id: item.product_variant_id,
|
||||
cantidad: item.cantidad
|
||||
}))
|
||||
};
|
||||
|
||||
const response = await this.checkoutService.createPurchase(tenant.codigo, payload);
|
||||
|
||||
Reference in New Issue
Block a user