mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 11:38:56 +00:00
Additive-only: pages still use lib/api/* and constants/queryKeys.ts until the page-migration agents run. Each domain ships api.ts (HTTP moved from lib/api), types.ts (contract re-exports + view types), schemas.ts (contract schema re-exports + form schemas with toRequest mappers), and use-cases.ts (TanStack Query v5 hooks + hierarchical query keys, mirroring current page invalidations and toast-on-error behavior). Adds an explicit vite/vitest alias for the @proposal-system/api-contracts/schemas subpath (package has no exports map) plus a schema/mapper smoke test suite.
40 lines
1.5 KiB
TypeScript
40 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;
|
|
},
|
|
};
|