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 { 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>(
|
||||
|
||||
@@ -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[];
|
||||
|
||||
Reference in New Issue
Block a user