refactor(checkout): remove purchase item editing client

This commit is contained in:
2026-08-21 11:05:39 -03:00
parent 0bd6dc3b22
commit 3e9e35c681
3 changed files with 17 additions and 115 deletions

View File

@@ -3,7 +3,6 @@ import { firstValueFrom } from 'rxjs';
import { environment } from '../../../environments/environment';
import { BaseApiService } from './base-api.service';
import { CartItemVariant } from './cart/cart.interface';
export interface UpdatePurchaseCustomerPayload {
dni: string;
@@ -74,7 +73,6 @@ export interface PurchaseDetailItemResponse {
line_total: string;
source_catalog_item_id: number | null;
source_variant_id: number | null;
variants?: CartItemVariant[];
item_details: {
nombre: string;
descripcion: string | null;
@@ -97,7 +95,7 @@ export interface PurchaseDetailResponse extends PurchaseStatusResponse {
telefono: string | null;
nombre_apellido: string | null;
email: string | null;
items_source: 'purchase' | 'cart';
items_source: 'purchase';
items: PurchaseDetailItemResponse[];
tickets_count?: number;
has_generated_tickets?: boolean;
@@ -171,104 +169,6 @@ export class CheckoutService extends BaseApiService {
return purchase;
}
async updateItemQuantity(
tenantCode: string,
purchaseId: number,
itemId: number,
quantity: number,
cartId: number | null = null,
itemsSource: 'purchase' | 'cart' = 'purchase',
): Promise<PurchaseDetailResponse> {
if (itemsSource === 'cart' && cartId !== null) {
await firstValueFrom(
this.http.patch(
`${environment.url}tenants/${tenantCode}/checkout-carts/${cartId}/items/${itemId}`,
{ cantidad: quantity },
),
);
return this.getPurchase(tenantCode, purchaseId);
}
const response = await firstValueFrom(
this.http.patch<{ data?: PurchaseDetailResponse } | PurchaseDetailResponse>(
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/items/${itemId}`,
{ quantity },
),
);
const purchase = this.extractResponseData<PurchaseDetailResponse>(response);
if (!purchase) {
throw new Error('Error al actualizar la cantidad del producto.');
}
return purchase;
}
async updateItemVariant(
tenantCode: string,
purchaseId: number,
itemId: number,
variantId: number,
quantity: number,
cartId: number | null = null,
itemsSource: 'purchase' | 'cart' = 'purchase',
): Promise<PurchaseDetailResponse> {
if (itemsSource === 'cart' && cartId !== null) {
await firstValueFrom(
this.http.patch(
`${environment.url}tenants/${tenantCode}/checkout-carts/${cartId}/items/${itemId}`,
{ cantidad: quantity, variant_id: variantId },
),
);
} else {
await firstValueFrom(
this.http.patch(
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/items/${itemId}`,
{ quantity, variant_id: variantId },
),
);
}
return this.getPurchase(tenantCode, purchaseId);
}
async removeItem(
tenantCode: string,
purchaseId: number,
itemId: number,
cartId: number | null = null,
itemsSource: 'purchase' | 'cart' = 'purchase',
): Promise<PurchaseDetailResponse> {
const url =
itemsSource === 'cart' && cartId !== null
? `${environment.url}tenants/${tenantCode}/checkout-carts/${cartId}/items/${itemId}`
: `${environment.url}tenants/${tenantCode}/compras/${purchaseId}/items/${itemId}`;
await firstValueFrom(this.http.delete(url));
return this.getPurchase(tenantCode, purchaseId);
}
async prepareItemEditing(
tenantCode: string,
purchaseId: number,
): Promise<PurchaseDetailResponse> {
const response = await firstValueFrom(
this.http.post<{ data?: PurchaseDetailResponse } | PurchaseDetailResponse>(
`${environment.url}tenants/${tenantCode}/compras/${purchaseId}/edit-items`,
{},
),
);
const purchase = this.extractResponseData<PurchaseDetailResponse>(response);
if (!purchase) {
throw new Error('Error al preparar la compra para editarla.');
}
return purchase;
}
async completePurchase(tenantCode: string, purchaseId: number): Promise<PurchaseStatusResponse> {
const response = await firstValueFrom(
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(

View File

@@ -10,6 +10,14 @@ export interface CartEditingPolicy {
allow_update_variant: boolean;
}
export interface CheckoutEditingPolicy extends CartEditingPolicy {
code: 'disabled';
allow_modify: false;
allow_delete: false;
allow_update_quantity: false;
allow_update_variant: false;
}
export interface BankAccount {
id: number;
tenant_code: string;
@@ -140,7 +148,7 @@ export interface Tenant {
display_seach_bar?: boolean;
display_cart?: boolean;
cart_editing_policy?: CartEditingPolicy;
checkout_editing_policy?: CartEditingPolicy;
checkout_editing_policy?: CheckoutEditingPolicy;
display_cart_item_images?: boolean;
social_media?: SocialMedia[];
menues?: Menu[];

View File

@@ -13,16 +13,13 @@ import { CatalogService } from '../../../../core/services/catalog/catalog.servic
import { GlobalLoadingService } from '../../../../core/services/global-loading/global-loading.service';
import { TenantService } from '../../../../core/services/tenant.service';
import { ToastService } from '../../../../core/services/toast.service';
import { CartEditingPolicy } from '../../../../core/services/tenant.interface';
import { CheckoutEditingPolicy } from '../../../../core/services/tenant.interface';
import { CheckoutPageComponent } from './checkout-page.component';
describe('CheckoutPageComponent payment validation', () => {
let checkoutServiceStub: {
startCheckout: ReturnType<typeof vi.fn>;
updateCustomerData: ReturnType<typeof vi.fn>;
updateItemQuantity: ReturnType<typeof vi.fn>;
updateItemVariant: ReturnType<typeof vi.fn>;
removeItem: ReturnType<typeof vi.fn>;
cancelPurchase: ReturnType<typeof vi.fn>;
generatePaymentIntent: ReturnType<typeof vi.fn>;
submitPurchaseForReview: ReturnType<typeof vi.fn>;
@@ -46,7 +43,7 @@ describe('CheckoutPageComponent payment validation', () => {
let tenantState: ReturnType<
typeof signal<{
codigo: string;
checkout_editing_policy?: CartEditingPolicy;
checkout_editing_policy?: CheckoutEditingPolicy;
}>
>;
@@ -69,9 +66,6 @@ describe('CheckoutPageComponent payment validation', () => {
total: '0.00',
}),
updateCustomerData: vi.fn(),
updateItemQuantity: vi.fn(),
updateItemVariant: vi.fn(),
removeItem: vi.fn(),
cancelPurchase: vi.fn().mockResolvedValue({ status: 'cancelled' }),
generatePaymentIntent: vi.fn().mockResolvedValue({
qr_data: { qr_code: 'qr-value' },
@@ -110,11 +104,11 @@ describe('CheckoutPageComponent payment validation', () => {
tenantState = signal({
codigo: 'tenant-test',
checkout_editing_policy: {
code: 'full',
allow_modify: true,
allow_delete: true,
allow_update_quantity: true,
allow_update_variant: true,
code: 'disabled',
allow_modify: false,
allow_delete: false,
allow_update_quantity: false,
allow_update_variant: false,
},
});