x
This commit is contained in:
1 parent
913cbef765
commit
173c583787
22 files changed
+2847
-364
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { Article, Category, Order, Page, Product } from '@homaroma/types'
|
||||
import type { Article, Category, Order, Page, Product, ProductDetailSection } from '@homaroma/types'
|
||||
import { API_BASE } from './api'
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
@@ -19,6 +19,18 @@ export type Coupon = {
|
||||
expiresAt?: string | null
|
||||
}
|
||||
|
||||
export type ProductReview = {
|
||||
id: number
|
||||
rating: number
|
||||
comment?: string | null
|
||||
customerName?: string | null
|
||||
createdAt: string
|
||||
customer?: {
|
||||
displayName?: string | null
|
||||
pictureUrl?: string | null
|
||||
} | null
|
||||
}
|
||||
|
||||
export type ApiResult<T> =
|
||||
| { ok: true; data: T }
|
||||
| { ok: false; error: string; status?: number }
|
||||
@@ -104,6 +116,14 @@ export async function getProductResult(id: string | number, lang = 'all'): Promi
|
||||
return await fetchJsonResult<Product>(`/products/${id}?lang=${lang}`, { next: { revalidate: defaultRevalidate } })
|
||||
}
|
||||
|
||||
export async function getProductDetailSectionsResult(id: string | number, lang = 'all'): Promise<ApiResult<ProductDetailSection[]>> {
|
||||
return await fetchJsonResult<ProductDetailSection[]>(`/products/${id}/detail-sections?lang=${lang}`, { next: { revalidate: defaultRevalidate } })
|
||||
}
|
||||
|
||||
export async function getProductReviewsResult(id: string | number): Promise<ApiResult<ProductReview[]>> {
|
||||
return await fetchJsonResult<ProductReview[]>(`/reviews/product/${id}`, { next: { revalidate: defaultRevalidate } })
|
||||
}
|
||||
|
||||
export async function getProducts(query = '', lang = 'all'): Promise<Product[]> {
|
||||
const separator = query ? '&' : ''
|
||||
const response = await fetchJson<ProductListResponse>(`/products?${query}${separator}lang=${lang}`, {
|
||||
|
||||
Reference in new issue
Block a user