feat(purchase): enhance purchase detail and summary interfaces, update purchase item component for improved data handling
This commit is contained in:
@@ -16,6 +16,51 @@ export interface PurchaseStatusResponse {
|
||||
status: string | null;
|
||||
}
|
||||
|
||||
export interface PurchaseSummaryResponse extends PurchaseStatusResponse {
|
||||
id: number;
|
||||
created_at: string | null;
|
||||
total: string;
|
||||
}
|
||||
|
||||
export interface PurchaseDetailAttributeResponse {
|
||||
name: string;
|
||||
value: string | null;
|
||||
}
|
||||
|
||||
export interface PurchaseDetailItemResponse {
|
||||
id: number;
|
||||
quantity: number;
|
||||
unit_price: string;
|
||||
line_total: string;
|
||||
product: {
|
||||
id: number;
|
||||
nombre: string;
|
||||
slug: string;
|
||||
imagen: string | null;
|
||||
} | null;
|
||||
variant: {
|
||||
id: number;
|
||||
attributes: PurchaseDetailAttributeResponse[];
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface PurchaseDetailResponse extends PurchaseStatusResponse {
|
||||
id: number;
|
||||
cart_id: number | null;
|
||||
tenant_codigo: string;
|
||||
user_id: number;
|
||||
created_at: string | null;
|
||||
payment_method: string | null;
|
||||
dni: string | null;
|
||||
telefono: string | null;
|
||||
nombre_apellido: string | null;
|
||||
email: string | null;
|
||||
items_source: 'purchase' | 'cart' | null;
|
||||
items: PurchaseDetailItemResponse[];
|
||||
subtotal: string;
|
||||
total: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -62,13 +107,13 @@ export class CheckoutService {
|
||||
};
|
||||
}
|
||||
|
||||
async getPurchases(tenantCode: string, status?: string): Promise<{ data: any[] }> {
|
||||
async getPurchases(tenantCode: string, status?: string): Promise<{ data: PurchaseSummaryResponse[] }> {
|
||||
let url = `${environment.url}tenants/${tenantCode}/compras`;
|
||||
if (status) {
|
||||
url += `?status=${status}`;
|
||||
}
|
||||
const response = await firstValueFrom(
|
||||
this.http.get<{ data: any[] }>(url)
|
||||
this.http.get<{ data: PurchaseSummaryResponse[] }>(url)
|
||||
);
|
||||
if (!response) {
|
||||
throw new Error('Error al obtener las compras.');
|
||||
@@ -76,20 +121,18 @@ export class CheckoutService {
|
||||
return response;
|
||||
}
|
||||
|
||||
async getPurchase(tenantCode: string, purchaseId: string | number): Promise<PurchaseStatusResponse> {
|
||||
async getPurchase(tenantCode: string, purchaseId: string | number): Promise<PurchaseDetailResponse> {
|
||||
const response = await firstValueFrom(
|
||||
this.http.get<{ data?: PurchaseStatusResponse } | PurchaseStatusResponse>(`${environment.url}tenants/${tenantCode}/compras/${purchaseId}`)
|
||||
this.http.get<{ data?: PurchaseDetailResponse } | PurchaseDetailResponse>(`${environment.url}tenants/${tenantCode}/compras/${purchaseId}`)
|
||||
);
|
||||
|
||||
const purchase = this.extractResponseData<PurchaseStatusResponse>(response);
|
||||
const purchase = this.extractResponseData<PurchaseDetailResponse>(response);
|
||||
|
||||
if (!purchase) {
|
||||
throw new Error('Error al obtener la compra.');
|
||||
}
|
||||
|
||||
return {
|
||||
status: purchase.status ?? null
|
||||
};
|
||||
return purchase;
|
||||
}
|
||||
|
||||
private extractResponseData<T>(response: T | { data?: T } | null | undefined): T | null {
|
||||
|
||||
Reference in New Issue
Block a user