23 lines
570 B
TypeScript
23 lines
570 B
TypeScript
export type Product = {
|
|
id: number;
|
|
title: string;
|
|
price_cents: number;
|
|
image_url: string;
|
|
};
|
|
|
|
export async function fetchProducts(): Promise<Product[]> {
|
|
const res = await fetch("/api/products", { cache: "no-store" });
|
|
if (!res.ok) {
|
|
throw new Error("Failed to fetch products");
|
|
}
|
|
return res.json();
|
|
}
|
|
|
|
export async function fetchProduct(productId: string): Promise<Product> {
|
|
const res = await fetch(`/api/products/${productId}`, { cache: "no-store" });
|
|
if (!res.ok) {
|
|
throw new Error("Failed to fetch product");
|
|
}
|
|
return res.json();
|
|
}
|