mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
household address: chain API call
This commit is contained in:
parent
e14a125bf3
commit
1b36d9b1ab
@ -91,7 +91,7 @@ const postAddress = (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',
|
||||
|
@ -38,22 +38,13 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
householdId: window.householdId,
|
||||
validFrom: new Date()
|
||||
validFrom: new Date().toISOString().split('T')[0]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
newAddress() {
|
||||
return this.$store.state.newAddress;
|
||||
},
|
||||
validFrom: {
|
||||
set(value) {
|
||||
console.log('value', value);
|
||||
this.validFrom = value;
|
||||
},
|
||||
get() {
|
||||
return this.validFrom;
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
addNewAddress({ address, modal }) {
|
||||
@ -82,21 +73,11 @@ export default {
|
||||
modal.showModal = false;
|
||||
},
|
||||
addToHousehold() {
|
||||
const householdId = this.householdId;
|
||||
const addressId = this.$store.state.newAddress.address_id;
|
||||
console.log(householdId);
|
||||
console.log(addressId);
|
||||
console.log(this.validFrom)
|
||||
// TODO: Chainer l'ajout de la date puis l'ajout de l'addresse au ménage
|
||||
this.$store.dispatch('addDateToAddress', {
|
||||
addressId,
|
||||
body: {
|
||||
validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}
|
||||
}
|
||||
}
|
||||
);
|
||||
this.$store.dispatch('addAddressToHousehold', {householdId, addressId});
|
||||
|
||||
this.$store.dispatch('addDateToAddressAndAddressToHousehold', {
|
||||
householdId: this.householdId,
|
||||
addressId: this.$store.state.newAddress.address_id,
|
||||
body: { validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}}
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -4,7 +4,8 @@ const appMessages = {
|
||||
fr: {
|
||||
select_a_existing_address: 'Sélectionner une adresse existante',
|
||||
create_a_new_address: 'Créer une nouvelle adresse',
|
||||
add_an_address_to_household: 'Ajouter l\'adresse au ménage'
|
||||
add_an_address_to_household: 'Ajouter l\'adresse au ménage',
|
||||
validFrom: 'Date du déménagement'
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,7 @@ const store = createStore({
|
||||
state: {
|
||||
newAddress: {},
|
||||
household: {},
|
||||
validFrom: {},
|
||||
errorMsg: []
|
||||
},
|
||||
getters: {
|
||||
@ -46,9 +47,13 @@ const store = createStore({
|
||||
commit('catchError', error);
|
||||
});
|
||||
},
|
||||
addAddressToHousehold({ commit }, payload) {
|
||||
console.log('@A addAddressToHousehold payload', payload);
|
||||
addDateToAddressAndAddressToHousehold({ commit }, payload) {
|
||||
console.log('@A addDateToAddressAndAddressToHousehold payload', payload);
|
||||
|
||||
patchAddress(payload.addressId, payload.body)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('addDateToAddress', address.validFrom);
|
||||
resolve().then(
|
||||
postAddressToHousehold(payload.householdId, payload.addressId)
|
||||
.then(household => new Promise((resolve, reject) => {
|
||||
commit('addAddressToHousehold', household);
|
||||
@ -56,14 +61,8 @@ 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user