person: post an address when creating a person

This commit is contained in:
nobohan 2022-04-15 13:41:47 +02:00
parent bea019e9bc
commit 57ed90a696
2 changed files with 75 additions and 11 deletions

View File

@ -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 {

View File

@ -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)