refactor(checkout): remove purchase item editing client
This commit is contained in:
@@ -3,7 +3,6 @@ import { firstValueFrom } from 'rxjs';
|
|||||||
|
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
import { BaseApiService } from './base-api.service';
|
import { BaseApiService } from './base-api.service';
|
||||||
import { CartItemVariant } from './cart/cart.interface';
|
|
||||||
|
|
||||||
export interface UpdatePurchaseCustomerPayload {
|
export interface UpdatePurchaseCustomerPayload {
|
||||||
dni: string;
|
dni: string;
|
||||||
@@ -74,7 +73,6 @@ export interface PurchaseDetailItemResponse {
|
|||||||
line_total: string;
|
line_total: string;
|
||||||
source_catalog_item_id: number | null;
|
source_catalog_item_id: number | null;
|
||||||
source_variant_id: number | null;
|
source_variant_id: number | null;
|
||||||
variants?: CartItemVariant[];
|
|
||||||
item_details: {
|
item_details: {
|
||||||
nombre: string;
|
nombre: string;
|
||||||
descripcion: string | null;
|
descripcion: string | null;
|
||||||
@@ -97,7 +95,7 @@ export interface PurchaseDetailResponse extends PurchaseStatusResponse {
|
|||||||
telefono: string | null;
|
telefono: string | null;
|
||||||
nombre_apellido: string | null;
|
nombre_apellido: string | null;
|
||||||
email: string | null;
|
email: string | null;
|
||||||
items_source: 'purchase' | 'cart';
|
items_source: 'purchase';
|
||||||
items: PurchaseDetailItemResponse[];
|
items: PurchaseDetailItemResponse[];
|
||||||
tickets_count?: number;
|
tickets_count?: number;
|
||||||
has_generated_tickets?: boolean;
|
has_generated_tickets?: boolean;
|
||||||
@@ -171,104 +169,6 @@ export class CheckoutService extends BaseApiService {
|
|||||||
return purchase;
|
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> {
|
async completePurchase(tenantCode: string, purchaseId: number): Promise<PurchaseStatusResponse> {
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(
|
this.http.post<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ export interface CartEditingPolicy {
|
|||||||
allow_update_variant: boolean;
|
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 {
|
export interface BankAccount {
|
||||||
id: number;
|
id: number;
|
||||||
tenant_code: string;
|
tenant_code: string;
|
||||||
@@ -140,7 +148,7 @@ export interface Tenant {
|
|||||||
display_seach_bar?: boolean;
|
display_seach_bar?: boolean;
|
||||||
display_cart?: boolean;
|
display_cart?: boolean;
|
||||||
cart_editing_policy?: CartEditingPolicy;
|
cart_editing_policy?: CartEditingPolicy;
|
||||||
checkout_editing_policy?: CartEditingPolicy;
|
checkout_editing_policy?: CheckoutEditingPolicy;
|
||||||
display_cart_item_images?: boolean;
|
display_cart_item_images?: boolean;
|
||||||
social_media?: SocialMedia[];
|
social_media?: SocialMedia[];
|
||||||
menues?: Menu[];
|
menues?: Menu[];
|
||||||
|
|||||||
@@ -13,16 +13,13 @@ import { CatalogService } from '../../../../core/services/catalog/catalog.servic
|
|||||||
import { GlobalLoadingService } from '../../../../core/services/global-loading/global-loading.service';
|
import { GlobalLoadingService } from '../../../../core/services/global-loading/global-loading.service';
|
||||||
import { TenantService } from '../../../../core/services/tenant.service';
|
import { TenantService } from '../../../../core/services/tenant.service';
|
||||||
import { ToastService } from '../../../../core/services/toast.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';
|
import { CheckoutPageComponent } from './checkout-page.component';
|
||||||
|
|
||||||
describe('CheckoutPageComponent payment validation', () => {
|
describe('CheckoutPageComponent payment validation', () => {
|
||||||
let checkoutServiceStub: {
|
let checkoutServiceStub: {
|
||||||
startCheckout: ReturnType<typeof vi.fn>;
|
startCheckout: ReturnType<typeof vi.fn>;
|
||||||
updateCustomerData: 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>;
|
cancelPurchase: ReturnType<typeof vi.fn>;
|
||||||
generatePaymentIntent: ReturnType<typeof vi.fn>;
|
generatePaymentIntent: ReturnType<typeof vi.fn>;
|
||||||
submitPurchaseForReview: ReturnType<typeof vi.fn>;
|
submitPurchaseForReview: ReturnType<typeof vi.fn>;
|
||||||
@@ -46,7 +43,7 @@ describe('CheckoutPageComponent payment validation', () => {
|
|||||||
let tenantState: ReturnType<
|
let tenantState: ReturnType<
|
||||||
typeof signal<{
|
typeof signal<{
|
||||||
codigo: string;
|
codigo: string;
|
||||||
checkout_editing_policy?: CartEditingPolicy;
|
checkout_editing_policy?: CheckoutEditingPolicy;
|
||||||
}>
|
}>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@@ -69,9 +66,6 @@ describe('CheckoutPageComponent payment validation', () => {
|
|||||||
total: '0.00',
|
total: '0.00',
|
||||||
}),
|
}),
|
||||||
updateCustomerData: vi.fn(),
|
updateCustomerData: vi.fn(),
|
||||||
updateItemQuantity: vi.fn(),
|
|
||||||
updateItemVariant: vi.fn(),
|
|
||||||
removeItem: vi.fn(),
|
|
||||||
cancelPurchase: vi.fn().mockResolvedValue({ status: 'cancelled' }),
|
cancelPurchase: vi.fn().mockResolvedValue({ status: 'cancelled' }),
|
||||||
generatePaymentIntent: vi.fn().mockResolvedValue({
|
generatePaymentIntent: vi.fn().mockResolvedValue({
|
||||||
qr_data: { qr_code: 'qr-value' },
|
qr_data: { qr_code: 'qr-value' },
|
||||||
@@ -110,11 +104,11 @@ describe('CheckoutPageComponent payment validation', () => {
|
|||||||
tenantState = signal({
|
tenantState = signal({
|
||||||
codigo: 'tenant-test',
|
codigo: 'tenant-test',
|
||||||
checkout_editing_policy: {
|
checkout_editing_policy: {
|
||||||
code: 'full',
|
code: 'disabled',
|
||||||
allow_modify: true,
|
allow_modify: false,
|
||||||
allow_delete: true,
|
allow_delete: false,
|
||||||
allow_update_quantity: true,
|
allow_update_quantity: false,
|
||||||
allow_update_variant: true,
|
allow_update_variant: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user