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.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user