Initial commit: redefined-designs storefront
This commit is contained in:
Executable
+83
@@ -0,0 +1,83 @@
|
||||
export interface ItemImage {
|
||||
id: number;
|
||||
image_path: string;
|
||||
sort_order: number;
|
||||
}
|
||||
|
||||
export interface Item {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string | null;
|
||||
price_cents: number;
|
||||
images: ItemImage[];
|
||||
status: 'available' | 'reserved' | 'sold';
|
||||
}
|
||||
|
||||
export interface SiteConfig {
|
||||
paypalClientId: string | null;
|
||||
demoMode: boolean;
|
||||
currency: string;
|
||||
}
|
||||
|
||||
export async function fetchConfig(): Promise<SiteConfig> {
|
||||
const res = await fetch('/api/config');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchItems(): Promise<Item[]> {
|
||||
const res = await fetch('/api/items');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchAdminItems(): Promise<Item[]> {
|
||||
const res = await fetch('/api/admin/items');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function saveItem(id: number | null, formData: FormData): Promise<Item> {
|
||||
const url = id ? `/api/admin/items/${id}` : '/api/admin/items';
|
||||
const res = await fetch(url, { method: id ? 'PUT' : 'POST', body: formData });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function deleteItem(id: number): Promise<void> {
|
||||
await fetch(`/api/admin/items/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export async function deleteItemImage(itemId: number, imageId: number): Promise<void> {
|
||||
await fetch(`/api/admin/items/${itemId}/images/${imageId}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export async function markSold(id: number): Promise<Item> {
|
||||
const res = await fetch(`/api/admin/items/${id}/mark-sold`, { method: 'POST' });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function markAvailable(id: number): Promise<Item> {
|
||||
const res = await fetch(`/api/admin/items/${id}/mark-available`, { method: 'POST' });
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function createPaypalOrder(itemId: number): Promise<string> {
|
||||
const res = await fetch(`/api/checkout/paypal/${itemId}/create`, { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Could not start checkout');
|
||||
return data.orderID;
|
||||
}
|
||||
|
||||
export async function capturePaypalOrder(itemId: number, orderID: string): Promise<void> {
|
||||
const res = await fetch(`/api/checkout/paypal/${itemId}/capture`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ orderID })
|
||||
});
|
||||
if (!res.ok) throw new Error('Payment captured but confirmation failed — contact the seller.');
|
||||
}
|
||||
|
||||
export async function demoPurchase(itemId: number): Promise<void> {
|
||||
const res = await fetch(`/api/checkout/demo/${itemId}/purchase`, { method: 'POST' });
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error || 'Demo purchase failed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user