household address: patch address + add validFrom input

This commit is contained in:
nobohan 2021-06-08 21:14:09 +02:00
parent db77224b9f
commit 9375c2cf86
4 changed files with 67 additions and 5 deletions

View File

@ -278,7 +278,8 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_POST => true,
Request::METHOD_HEAD => true
Request::METHOD_HEAD => true,
Request::METHOD_PATCH => true
]
],
]

View File

@ -82,10 +82,37 @@ const postAddress = (address) => {
});
};
/*
* Endpoint chill_api_single_address__entity__create
* method PATCH, patch Address Instance
*
* @id integer - id of address
* @body Object - dictionary with changes to post
*/
const patchAddress = (id, body) => {
console.log('body', body);
const url = `/api/1.0/main/address/${id}.json`;
return fetch(url, {
method: 'PATCH',
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,
fetchAddresses,
postAddress
postAddress,
patchAddress
};

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ import { createStore } from 'vuex';
import { postAddress } from 'ChillMainAssets/vuejs/_api/AddAddress';
import { postAddressToHousehold } from '../api';
import { patchAddress } from '../../../../../../ChillMainBundle/Resources/public/vuejs/_api/AddAddress';
const debug = process.env.NODE_ENV !== 'production';
@ -26,6 +27,10 @@ const store = createStore({
addAddressToHousehold(state, household) {
console.log('@M addAddress address', household);
state.household = household;
},
addDateToAddress(state, validFrom) {
console.log('@M addAddress address', validFrom);
state.validFrom = validFrom;
}
},
actions: {
@ -52,7 +57,18 @@ const store = createStore({
.catch((error) => {
commit('catchError', error);
});
}
},
addDateToAddress({ commit }, payload) {
console.log('@A addAddressToHousehold payload', payload);
patchAddress(payload.addressId, payload.body)
.then(address => new Promise((resolve, reject) => {
commit('addDateToAddress', address.validFrom);
resolve();
}))
.catch((error) => {
commit('catchError', error);
});
},
}
});