diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue index b080cc52d..5949a1e56 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue @@ -240,13 +240,6 @@ export default { if (typeof data.profession !== 'undefined' && null !== data.profession) { data.profession = data.profession !== null ? {type: 'third_party_profession', id: data.profession.id} : null; } - if (null !== data.addressId) { - console.log(data) - //TODO make a good address object - // attach the addressId - // test if this condition is safe - - } // console.log('onthefly data', data); } } else { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index 66fe64579..5e57ae93d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -278,12 +278,82 @@ export default { }, saveFormOnTheFly({ type, data }) { console.log('saveFormOnTheFly from addPersons, type', type, ', data', data); - //TODO: create a household if address in data. if (type === 'person') { + makeFetch('POST', '/api/1.0/person/person.json', data) - .then(response => { - this.newPriorSuggestion(response); + .then(responsePerson => { + + this.newPriorSuggestion(responsePerson); this.$refs.onTheFly.closeModal(); + + if (null !== data.addressId) { + const household = { + 'type': 'household' + }; + const address = { + 'type': 'address', + 'id': data.addressId + }; + makeFetch('POST', '/api/1.0/person/household.json', household) + .then(responseHousehold => { + console.log(responseHousehold); + + const member = { + 'concerned': [ + { + 'person': { + 'type': 'person', + 'id': responsePerson.id + }, + "position": { + "type": "household_position", + "id": 4 //TODO, which position? + }, + } + ], + 'destination': { + 'type': 'household', + 'id': responseHousehold.id + } + }; + console.log(member); + makeFetch('POST', '/api/1.0/person/household/members/move.json', member) + .then(response => { + console.log(response); + makeFetch('POST', `/api/1.0/person/household/${responseHousehold.id}/address.json`, address) + .then(response => { + console.log(response); + }) + .catch((error) => { + if (error.name === 'ValidationException') { + for (let v of error.violations) { + this.$toast.open({message: v }); + } + } else { + this.$toast.open({message: 'An error occurred'}); + } + }); + }) + .catch((error) => { + if (error.name === 'ValidationException') { + for (let v of error.violations) { + this.$toast.open({message: v }); + } + } else { + this.$toast.open({message: 'An error occurred'}); + } + }); + }) + .catch((error) => { + if (error.name === 'ValidationException') { + for (let v of error.violations) { + this.$toast.open({message: v }); + } + } else { + this.$toast.open({message: 'An error occurred'}); + } + }); + } }) .catch((error) => { if (error.name === 'ValidationException') { @@ -293,7 +363,8 @@ export default { } else { this.$toast.open({message: 'An error occurred'}); } - }) + }); + } else if (type === 'thirdparty') { makeFetch('POST', '/api/1.0/thirdparty/thirdparty.json', data)