Quality / test (push) Canceled after 0s
Add the admin pricing observation and valuation form, secure valuation writes with CSRF, and extend authenticated browser coverage.
28 lines
949 B
JavaScript
28 lines
949 B
JavaScript
const apiBaseUrl = import.meta.env?.VITE_API_BASE_URL ?? '/api/v1';
|
|
|
|
async function request(path, options = {}) {
|
|
const response = await fetch(`${apiBaseUrl}${path}`, {
|
|
credentials: 'include',
|
|
...options,
|
|
headers: { ...(options.body ? { 'content-type': 'application/json' } : {}), ...options.headers },
|
|
});
|
|
const payload = await response.json().catch(() => null);
|
|
if (!response.ok) throw new Error(payload?.error?.message ?? 'Pricing request failed.');
|
|
return payload?.data;
|
|
}
|
|
|
|
export function addAdminPricingObservation(input, csrfToken) {
|
|
return request('/admin/pricing/observations', {
|
|
method: 'POST',
|
|
headers: { 'x-csrf-token': csrfToken },
|
|
body: JSON.stringify(input),
|
|
});
|
|
}
|
|
|
|
export function calculateAdminValuation(inventoryItemId, csrfToken) {
|
|
return request(`/admin/inventory/${encodeURIComponent(inventoryItemId)}/valuation`, {
|
|
method: 'POST',
|
|
headers: { 'x-csrf-token': csrfToken },
|
|
});
|
|
}
|