v0.1.14 - b2b portal
This commit is contained in:
+95
-1
@@ -29,6 +29,15 @@ import type {
|
||||
RawMaterial,
|
||||
RawMaterialCreateInput,
|
||||
RawMaterialPriceCreateInput,
|
||||
CatalogueProduct,
|
||||
CustomerPricing,
|
||||
CustomerVisibilityRow,
|
||||
DraftOrderInput,
|
||||
Order,
|
||||
OrderingCustomer,
|
||||
OrderingCustomerUser,
|
||||
OrderingNotificationSettings,
|
||||
XeroStatus,
|
||||
Scenario,
|
||||
ThroughputEntry,
|
||||
ThroughputEntryCreateInput,
|
||||
@@ -486,5 +495,90 @@ export const api = {
|
||||
request<ClientAccessAccount>(`/api/client-access/features/${featureId}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(payload)
|
||||
}, 'manager')
|
||||
}, 'manager'),
|
||||
|
||||
// --- B2B ordering portal (customer) ---------------------------------------
|
||||
ordering: {
|
||||
catalogue: (params?: { category?: string; q?: string }, fetcher?: ApiFetch) => {
|
||||
const search = new URLSearchParams();
|
||||
if (params?.category) search.set('category', params.category);
|
||||
if (params?.q) search.set('q', params.q);
|
||||
const qs = search.toString();
|
||||
return cachedFetchJson<CatalogueProduct[]>(`/api/ordering/catalogue${qs ? `?${qs}` : ''}`, 'client', fetcher);
|
||||
},
|
||||
product: (productId: number, quantity = 1, fetcher?: ApiFetch) =>
|
||||
request<CatalogueProduct>(`/api/ordering/catalogue/${productId}?quantity=${quantity}`, { method: 'GET' }, 'client', fetcher),
|
||||
orders: (statusFilter?: string, fetcher?: ApiFetch) =>
|
||||
cachedFetchJson<Order[]>(`/api/ordering/orders${statusFilter ? `?status=${statusFilter}` : ''}`, 'client', fetcher),
|
||||
order: (orderId: number, fetcher?: ApiFetch) =>
|
||||
request<Order>(`/api/ordering/orders/${orderId}`, { method: 'GET' }, 'client', fetcher),
|
||||
createDraft: (payload: DraftOrderInput) =>
|
||||
request<Order>('/api/ordering/orders', { method: 'POST', body: JSON.stringify(payload) }, 'client'),
|
||||
updateDraft: (orderId: number, payload: Partial<DraftOrderInput>) =>
|
||||
request<Order>(`/api/ordering/orders/${orderId}`, { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
deleteDraft: (orderId: number) =>
|
||||
request<void>(`/api/ordering/orders/${orderId}`, { method: 'DELETE' }, 'client'),
|
||||
submit: (orderId: number, payload: Partial<DraftOrderInput> = {}) =>
|
||||
request<Order>(`/api/ordering/orders/${orderId}/submit`, { method: 'POST', body: JSON.stringify(payload) }, 'client'),
|
||||
reorder: (orderId: number) =>
|
||||
request<Order>(`/api/ordering/orders/${orderId}/reorder`, { method: 'POST' }, 'client'),
|
||||
confirmationPdf: (orderId: number) =>
|
||||
requestBlob(`/api/ordering/orders/${orderId}/confirmation.pdf`, {}, 'client')
|
||||
},
|
||||
|
||||
// --- B2B ordering portal (admin) ------------------------------------------
|
||||
orderingAdmin: {
|
||||
customers: (fetcher?: ApiFetch) => cachedFetchJson<OrderingCustomer[]>('/api/ordering-admin/customers', 'client', fetcher),
|
||||
createCustomer: (payload: { name: string; client_code: string; tenant_id?: string; notes?: string }) =>
|
||||
request<OrderingCustomer>('/api/ordering-admin/customers', { method: 'POST', body: JSON.stringify(payload) }, 'client'),
|
||||
updateCustomer: (customerId: number, payload: { name?: string; status?: string; notes?: string }) =>
|
||||
request<OrderingCustomer>(`/api/ordering-admin/customers/${customerId}`, { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
customerUsers: (customerId: number, fetcher?: ApiFetch) =>
|
||||
cachedFetchJson<OrderingCustomerUser[]>(`/api/ordering-admin/customers/${customerId}/users`, 'client', fetcher),
|
||||
createCustomerUser: (customerId: number, payload: { full_name: string; email: string; role: string }) =>
|
||||
request<OrderingCustomerUser>(`/api/ordering-admin/customers/${customerId}/users`, { method: 'POST', body: JSON.stringify(payload) }, 'client'),
|
||||
updateCustomerUser: (customerId: number, userId: number, payload: { full_name?: string; role?: string; status?: string }) =>
|
||||
request<OrderingCustomerUser>(`/api/ordering-admin/customers/${customerId}/users/${userId}`, { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
products: (fetcher?: ApiFetch) => cachedFetchJson<CatalogueProduct[]>('/api/ordering-admin/products', 'client', fetcher),
|
||||
createProduct: (payload: Partial<CatalogueProduct>) =>
|
||||
request<CatalogueProduct>('/api/ordering-admin/products', { method: 'POST', body: JSON.stringify(payload) }, 'client'),
|
||||
updateProduct: (productId: number, payload: Partial<CatalogueProduct>) =>
|
||||
request<CatalogueProduct>(`/api/ordering-admin/products/${productId}`, { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
visibility: (customerId: number, fetcher?: ApiFetch) =>
|
||||
cachedFetchJson<CustomerVisibilityRow[]>(`/api/ordering-admin/customers/${customerId}/visibility`, 'client', fetcher),
|
||||
setVisibility: (customerId: number, payload: { product_id: number; visible: boolean }) =>
|
||||
request(`/api/ordering-admin/customers/${customerId}/visibility`, { method: 'PUT', body: JSON.stringify(payload) }, 'client'),
|
||||
pricing: (customerId: number, fetcher?: ApiFetch) =>
|
||||
cachedFetchJson<CustomerPricing>(`/api/ordering-admin/customers/${customerId}/pricing`, 'client', fetcher),
|
||||
setAssignment: (customerId: number, payload: { price_list_id: number | null; discount_percent: number }) =>
|
||||
request<CustomerPricing>(`/api/ordering-admin/customers/${customerId}/assignment`, { method: 'PUT', body: JSON.stringify(payload) }, 'client'),
|
||||
setProductPrice: (
|
||||
customerId: number,
|
||||
payload: { product_id: number; unit_price: number | null; rule_type: string; contract_reference?: string | null; notes?: string | null; active?: boolean }
|
||||
) => request<CustomerPricing>(`/api/ordering-admin/customers/${customerId}/product-prices`, { method: 'PUT', body: JSON.stringify(payload) }, 'client'),
|
||||
deleteProductPrice: (customerId: number, productId: number) =>
|
||||
request<void>(`/api/ordering-admin/customers/${customerId}/product-prices/${productId}`, { method: 'DELETE' }, 'client'),
|
||||
orders: (params?: { status?: string; customer_id?: number }, fetcher?: ApiFetch) => {
|
||||
const search = new URLSearchParams();
|
||||
if (params?.status) search.set('status', params.status);
|
||||
if (params?.customer_id != null) search.set('customer_id', String(params.customer_id));
|
||||
const qs = search.toString();
|
||||
return cachedFetchJson<Order[]>(`/api/ordering-admin/orders${qs ? `?${qs}` : ''}`, 'client', fetcher);
|
||||
},
|
||||
order: (orderId: number, fetcher?: ApiFetch) =>
|
||||
request<Order>(`/api/ordering-admin/orders/${orderId}`, { method: 'GET' }, 'client', fetcher),
|
||||
updateStatus: (orderId: number, payload: { to_status: string; note?: string }) =>
|
||||
request<Order>(`/api/ordering-admin/orders/${orderId}/status`, { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
overrideLine: (orderId: number, lineId: number, payload: { quantity?: number; unit_price?: number; reason?: string }) =>
|
||||
request<Order>(`/api/ordering-admin/orders/${orderId}/lines/${lineId}`, { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
reopen: (orderId: number, note?: string) =>
|
||||
request<Order>(`/api/ordering-admin/orders/${orderId}/reopen`, { method: 'POST', body: JSON.stringify({ note }) }, 'client'),
|
||||
sendToXero: (orderId: number) =>
|
||||
request<Order>(`/api/ordering-admin/orders/${orderId}/send-to-xero`, { method: 'POST' }, 'client'),
|
||||
notificationSettings: (fetcher?: ApiFetch) =>
|
||||
cachedFetchJson<OrderingNotificationSettings>('/api/ordering-admin/notification-settings', 'client', fetcher),
|
||||
updateNotificationSettings: (payload: Partial<OrderingNotificationSettings>) =>
|
||||
request<OrderingNotificationSettings>('/api/ordering-admin/notification-settings', { method: 'PATCH', body: JSON.stringify(payload) }, 'client'),
|
||||
xeroStatus: (fetcher?: ApiFetch) => cachedFetchJson<XeroStatus>('/api/ordering-admin/xero/status', 'client', fetcher)
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user