mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-07 15:08:58 +00:00
Closes WEB-M5 (web hand-duplicated wire types, standing drift risk): - shared/api-contracts: rewritten as the authoritative superset of the .NET DTOs (ProposalListItem/ProposalDetail with poNumber and submittedByName, line item requests, customers, pricing library, dashboard, audit, sites, auth, presigned upload, ApiProblem); stale Proposal/UpdateLineItemsRequest shapes removed - shared/api-contracts/src/schemas.ts: zod runtime schemas coupled to every wire type via `satisfies z.ZodType<T>` (schema/type drift is now a compile error); separate entrypoint so type-only consumers (mobile) never pull zod - web: imports @proposal-system/api-contracts (file: dep + tsconfig paths + vite preserveSymlinks); all 7 lib/api modules re-export shared types so page imports stay stable; enum unions tightened (PricingLibraryPage form state now ServiceCategory-typed) - fix(web): customer create/update sent a singular `address` field the API silently dropped (contract is addresses: string[], CustomerDtos.cs) - addresses now round-trip, extra addresses preserved on edit - api: ProblemDetails responses carry a machine-readable top-level `code` (SHOC error-code vocabulary): ValidationFailed, InvalidStateTransition, NotFound, Unauthorized, InternalError; new BusinessRuleException(code, message) maps to 422 with its code; GlobalExceptionHandlerTests cover the full mapping (wire contract) Cross-checked .NET DTOs vs TS types vs zod schemas with the orchestrator scanner (Gemini): core domains consistent; internal-only DTOs (FileDtos vendor/lambda surface, SimilarProposalDtos, UserDtos admin surface) intentionally uncovered. Verify: dotnet 166/166, web tsc + vitest 26/26 + build, mobile tsc, shared tsc all green.
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import apiClient from './client';
|
|
// Fix: WEB-M5 — types from the shared contracts package. Note: the API takes
|
|
// addresses: string[] (CustomerDtos.cs); the old local CreateCustomerRequest
|
|
// sent a singular `address` field the API silently dropped.
|
|
import type {
|
|
Customer,
|
|
CustomerListParams,
|
|
CreateCustomerRequest,
|
|
UpdateCustomerRequest,
|
|
PagedResponse,
|
|
} from '@proposal-system/api-contracts';
|
|
|
|
export type {
|
|
Customer,
|
|
CustomerListParams,
|
|
CreateCustomerRequest,
|
|
UpdateCustomerRequest,
|
|
} from '@proposal-system/api-contracts';
|
|
|
|
export type PagedCustomerResponse = PagedResponse<Customer>;
|
|
|
|
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;
|
|
},
|
|
};
|