mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 15:08:58 +00:00
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
|
|
// Customers domain — HTTP calls only (no hooks). Moved from lib/api/customers.ts.
|
||
|
|
import apiClient from '../../lib/api/client';
|
||
|
|
import type {
|
||
|
|
Customer,
|
||
|
|
CustomerListParams,
|
||
|
|
CreateCustomerRequest,
|
||
|
|
UpdateCustomerRequest,
|
||
|
|
PagedCustomerResponse,
|
||
|
|
} from './types';
|
||
|
|
|
||
|
|
export const customersApi = {
|
||
|
|
/** GET /api/customers?query=<q> — search autocomplete (unchanged). */
|
||
|
|
search: async (query?: string): Promise<Customer[]> => {
|
||
|
|
const params = query ? `?query=${encodeURIComponent(query)}` : '';
|
||
|
|
const res = await apiClient.get(`/customers${params}`);
|
||
|
|
return res.data;
|
||
|
|
},
|
||
|
|
|
||
|
|
/** GET /api/customers/list?page=&pageSize= — paginated management list (admin/sysadmin). */
|
||
|
|
list: async (params: CustomerListParams = {}): Promise<PagedCustomerResponse> => {
|
||
|
|
const qs = new URLSearchParams();
|
||
|
|
if (params.page) qs.append('page', String(params.page));
|
||
|
|
if (params.pageSize) qs.append('pageSize', String(params.pageSize));
|
||
|
|
if (params.search) qs.append('search', params.search);
|
||
|
|
const res = await apiClient.get(`/customers/list?${qs.toString()}`);
|
||
|
|
return res.data;
|
||
|
|
},
|
||
|
|
|
||
|
|
/** POST /api/customers — create a new customer. */
|
||
|
|
create: async (data: CreateCustomerRequest): Promise<Customer> => {
|
||
|
|
const res = await apiClient.post('/customers', data);
|
||
|
|
return res.data;
|
||
|
|
},
|
||
|
|
|
||
|
|
/** PUT /api/customers/{id} — update an existing customer (admin/sysadmin). */
|
||
|
|
update: async (id: string, data: UpdateCustomerRequest): Promise<Customer> => {
|
||
|
|
const res = await apiClient.put(`/customers/${id}`, data);
|
||
|
|
return res.data;
|
||
|
|
},
|
||
|
|
};
|