feat(F-132): completed feature
This commit is contained in:
@@ -11,7 +11,7 @@ interface CmsPage {
|
||||
const BASE = process.env.NEXT_PUBLIC_API_URL ?? 'http://127.0.0.1:3000';
|
||||
|
||||
export async function fetchCategories(): Promise<Category[]> {
|
||||
const res = await fetch(`${BASE}/categories/tree`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/categories/tree`);
|
||||
if (!res.ok) throw new Error(`Failed to fetch categories: ${res.status}`);
|
||||
const data = await res.json();
|
||||
return data.items ?? [];
|
||||
@@ -30,7 +30,7 @@ export async function fetchProducts(params?: {
|
||||
if (params?.q) sp.set('q', params.q);
|
||||
if (params?.categorySlug) sp.set('categorySlug', params.categorySlug);
|
||||
if (params?.brandSlug) sp.set('brandSlug', params.brandSlug);
|
||||
const res = await fetch(`${BASE}/products/search?${sp}`, { cache: 'no-store', credentials: 'include' });
|
||||
const res = await fetch(`${BASE}/products/search?${sp}`, { credentials: 'include' });
|
||||
if (!res.ok) throw new Error(`Failed to fetch products: ${res.status}`);
|
||||
const data = await res.json();
|
||||
return data.items ?? [];
|
||||
@@ -48,35 +48,35 @@ export async function fetchSearchSuggestions(term: string): Promise<string[]> {
|
||||
}
|
||||
|
||||
export async function fetchBrandBySlug(slug: string): Promise<Brand | null> {
|
||||
const res = await fetch(`${BASE}/marca/${slug}`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/marca/${slug}`);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch brand: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchPage(slug: string): Promise<CmsPage | null> {
|
||||
const res = await fetch(`${BASE}/cms/pages/${slug}`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/cms/pages/${slug}`);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch page: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchBrands(): Promise<Brand[]> {
|
||||
const res = await fetch(`${BASE}/brands`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/brands`);
|
||||
if (!res.ok) throw new Error(`Failed to fetch brands: ${res.status}`);
|
||||
const data = await res.json();
|
||||
return data.items ?? [];
|
||||
}
|
||||
|
||||
export async function fetchCategoryBySlug(slug: string): Promise<Category | null> {
|
||||
const res = await fetch(`${BASE}/categoria/${slug}`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/categoria/${slug}`);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch category: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchProductBySlug(slug: string): Promise<Product | null> {
|
||||
const res = await fetch(`${BASE}/productos/${slug}`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/productos/${slug}`);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch product: ${res.status}`);
|
||||
return res.json();
|
||||
@@ -103,21 +103,21 @@ export interface StockAvailability {
|
||||
}
|
||||
|
||||
export async function fetchProductVariants(productId: string): Promise<ProductVariant[]> {
|
||||
const res = await fetch(`${BASE}/products/${productId}/variants`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/products/${productId}/variants`);
|
||||
if (!res.ok) throw new Error(`Failed to fetch variants: ${res.status}`);
|
||||
const data = await res.json();
|
||||
return data.items ?? [];
|
||||
}
|
||||
|
||||
export async function fetchVariantPrice(variantId: string): Promise<VariantPrice | null> {
|
||||
const res = await fetch(`${BASE}/pricing/variants/${variantId}`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/pricing/variants/${variantId}`);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Failed to fetch price: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchStockAvailability(variantId: string): Promise<StockAvailability> {
|
||||
const res = await fetch(`${BASE}/inventory/${variantId}/availability`, { cache: 'no-store' });
|
||||
const res = await fetch(`${BASE}/inventory/${variantId}/availability`);
|
||||
if (!res.ok) throw new Error(`Failed to fetch stock: ${res.status}`);
|
||||
return res.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user