mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Implemented `getPostalCodes` function in `local-search` driver and connected it with `AddressPicker.vue`. Introduced UI changes to display postal codes alongside addresses and ensured search requests are abortable.
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { TranslatableString } from "ChillMainAssets/types";
|
|
|
|
export interface AddressAggregated {
|
|
row_number: number;
|
|
street: string;
|
|
postcode_id: number;
|
|
code: string;
|
|
label: string;
|
|
positions: Record<string, string>;
|
|
}
|
|
|
|
export interface AssociatedPostalCode {
|
|
postcode_id: number;
|
|
code: string;
|
|
label: string;
|
|
country_id: number;
|
|
country_code: string;
|
|
country_name: TranslatableString;
|
|
}
|
|
|
|
/**
|
|
* @throws {DOMException} when fetch is aborted, the property name is always equals to 'AbortError'
|
|
*/
|
|
export const getAddressesAggregated = async (
|
|
search: string,
|
|
abortController: AbortController,
|
|
): Promise<AddressAggregated[]> => {
|
|
const params = new URLSearchParams({ q: search.trim() });
|
|
let response = null;
|
|
|
|
response = await fetch(
|
|
`/api/1.0/main/address-reference/aggregated/search?${params}`,
|
|
{ signal: abortController.signal },
|
|
);
|
|
|
|
if (response.ok) {
|
|
return await response.json();
|
|
}
|
|
|
|
throw new Error(response.statusText);
|
|
};
|
|
|
|
export const getPostalCodes = async (
|
|
search: string,
|
|
abortController: AbortController,
|
|
): Promise<AssociatedPostalCode[]> => {
|
|
const params = new URLSearchParams({ q: search.trim() });
|
|
let response = null;
|
|
|
|
response = await fetch(
|
|
`/api/1.0/main/address-reference/postal-code/search?${params}`,
|
|
{ signal: abortController.signal },
|
|
);
|
|
|
|
if (response.ok) {
|
|
return await response.json();
|
|
}
|
|
|
|
throw new Error(response.statusText);
|
|
};
|