Files
pokemon-inventory/apps/web/src/services/admin-sale-service.js
T
fragginwagon 8e5ce80196
Quality / test (push) Canceled after 0s
feat: complete inventory image and sales workflows
Commit the working vertical slices for inventory image processing and the Sale workflow, including Sale history, audited voiding, multi-item persistence, admin UI, migrations, documentation, and tests.
2026-09-09 00:35:57 -04:00

39 lines
1.4 KiB
JavaScript

const apiBaseUrl = import.meta.env?.VITE_API_BASE_URL ?? '/api/v1';
export async function createAdminSale(input, csrfToken) {
const response = await fetch(`${apiBaseUrl}/admin/sales`, {
method: 'POST',
credentials: 'include',
headers: {
'content-type': 'application/json',
'x-csrf-token': csrfToken,
},
body: JSON.stringify(input),
});
const payload = await response.json().catch(() => null);
if (!response.ok) throw new Error(payload?.error?.message ?? 'Sale request failed.');
return payload?.data;
}
export async function listAdminSales() {
const response = await fetch(`${apiBaseUrl}/admin/sales`, { credentials: 'include' });
const payload = await response.json().catch(() => null);
if (!response.ok) throw new Error(payload?.error?.message ?? 'Sale history is unavailable.');
return payload?.data ?? [];
}
export async function voidAdminSale(id, reason, csrfToken) {
const response = await fetch(`${apiBaseUrl}/admin/sales/${encodeURIComponent(id)}/void`, {
method: 'POST',
credentials: 'include',
headers: {
'content-type': 'application/json',
'x-csrf-token': csrfToken,
},
body: JSON.stringify({ reason }),
});
const payload = await response.json().catch(() => null);
if (!response.ok) throw new Error(payload?.error?.message ?? 'Sale correction failed.');
return payload?.data;
}