post new address - WIP

This commit is contained in:
nobohan
2021-05-25 17:54:21 +02:00
parent e88e9b1a6f
commit 72795be040
4 changed files with 80 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/*
* Endpoint chill_api_single_country_index
* Endpoint chill_api_single_country__index
* method GET, get Country Object
* @returns {Promise} a promise containing all Country object
*/
@@ -15,7 +15,7 @@ const fetchCountries = () => {
};
/*
* Endpoint chill_api_single_postal_code_index
* Endpoint chill_api_single_postal_code__index
* method GET, get Country Object
* @returns {Promise} a promise containing all Postal Code objects filtered with country
*/
@@ -30,9 +30,9 @@ const fetchCities = (country) => {
};
/*
* Endpoint chill_api_single_address_reference_index
* Endpoint chill_api_single_address_reference__index
* method GET, get AddressReference Object
* @returns {Promise} a promise containing all AddressReference objects filtered with country
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
*/
const fetchReferenceAddresses = (postalCode) => {
console.log('<<< fetching references addresses for', postalCode);
@@ -45,8 +45,31 @@ const fetchReferenceAddresses = (postalCode) => {
});
};
/*
* Endpoint chill_api_single_address__entity__create
* method POST, post Address Object
* @returns {Promise}
*/
const postAddress = (address) => {
console.log(address);
const url = `/api/1.0/main/address.json?`;
const body = address;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(body)
}).then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
export {
fetchCountries,
fetchCities,
fetchReferenceAddresses
fetchReferenceAddresses,
postAddress
};