household address: choose among available address

This commit is contained in:
nobohan
2021-06-07 12:18:03 +02:00
parent 6f68349f57
commit 2b5ed5e5a3
6 changed files with 134 additions and 32 deletions

View File

@@ -36,7 +36,6 @@ const fetchCities = (country) => {
*/
const fetchReferenceAddresses = (postalCode) => {
console.log('<<< fetching references addresses for', postalCode);
//TODO deal with huge number of addresses... we should do suggestion...
const url = `/api/1.0/main/address-reference.json?item_per_page=1000&postal_code=${postalCode.id}`;
return fetch(url)
.then(response => {
@@ -45,6 +44,22 @@ const fetchReferenceAddresses = (postalCode) => {
});
};
/*
* Endpoint chill_api_single_address_reference__index
* method GET, get AddressReference Object
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
*/
const fetchAddresses = () => {
console.log('<<< fetching addresses');
//TODO deal with huge number of addresses... we should do suggestion...
const url = `/api/1.0/main/address.json?item_per_page=1000`;
return fetch(url)
.then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
/*
* Endpoint chill_api_single_address__entity__create
* method POST, post Address Object
@@ -71,5 +86,6 @@ export {
fetchCountries,
fetchCities,
fetchReferenceAddresses,
fetchAddresses,
postAddress
};