refinement phase 4
This commit is contained in:
@@ -5,11 +5,14 @@ import type { CreateAddressInput, CustomerAddress, CustomerAddressDto, Addresses
|
||||
|
||||
const BASE = '/api/v1/customer_addresses';
|
||||
|
||||
// The wire `CustomerAddressDto` has no `provinceId` (REQ-009). Reads default it to null; writes
|
||||
// echo the caller's chosen province onto the returned row so the just-saved address can be
|
||||
// re-edited with its cascade prefilled (not yet persisted server-side).
|
||||
function toAddress(dto: CustomerAddressDto, provinceId?: number | null): CustomerAddress {
|
||||
return { ...dto, provinceId: provinceId ?? null };
|
||||
// REQ-009 (delivered): the wire `CustomerAddressDto` now carries `provinceId` (joined from
|
||||
// `cities.province_id`), so a freshly-fetched address prefills the cascade. The caller's chosen
|
||||
// province is kept as a fallback for the optimistic just-saved echo.
|
||||
interface AddressWire extends CustomerAddressDto {
|
||||
provinceId: number;
|
||||
}
|
||||
function toAddress(dto: AddressWire, provinceId?: number | null): CustomerAddress {
|
||||
return { ...dto, provinceId: dto.provinceId ?? provinceId ?? null };
|
||||
}
|
||||
|
||||
// Only the contract fields cross the wire. `latitude`/`longitude` are the picked pin (REQ-008 —
|
||||
@@ -43,7 +46,7 @@ export const addressesClientApi: AddressesApi = {
|
||||
// geo lookups' explicit `province_id`/`city_id`); match the patients template's `pageSize`.
|
||||
query.set('pageSize', String(params?.pageSize ?? ADDRESSES_PAGE_SIZE));
|
||||
const page = unwrap(
|
||||
await clientFetch<ApiEnvelope<Paginated<CustomerAddressDto>>>(`${BASE}/list?${query.toString()}`),
|
||||
await clientFetch<ApiEnvelope<Paginated<AddressWire>>>(`${BASE}/list?${query.toString()}`),
|
||||
);
|
||||
return { ...page, items: page.items.map((dto) => toAddress(dto)) };
|
||||
},
|
||||
@@ -51,7 +54,7 @@ export const addressesClientApi: AddressesApi = {
|
||||
create: async (input) =>
|
||||
toAddress(
|
||||
unwrap(
|
||||
await clientFetch<ApiEnvelope<CustomerAddressDto>>(`${BASE}/create`, {
|
||||
await clientFetch<ApiEnvelope<AddressWire>>(`${BASE}/create`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(toBody(input)),
|
||||
}),
|
||||
@@ -62,7 +65,7 @@ export const addressesClientApi: AddressesApi = {
|
||||
update: async (id, input) =>
|
||||
toAddress(
|
||||
unwrap(
|
||||
await clientFetch<ApiEnvelope<CustomerAddressDto>>(`${BASE}/update/${id}`, {
|
||||
await clientFetch<ApiEnvelope<AddressWire>>(`${BASE}/update/${id}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(toBody(input)),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user