person: on-the-fly person: first implementation of makeFetch for posting person

This commit is contained in:
nobohan 2022-01-10 18:11:02 +01:00
parent 15342f85d3
commit 378f3a16fc
2 changed files with 16 additions and 7 deletions

View File

@ -86,6 +86,7 @@ const ValidationException = (response) => {
const error = {}; const error = {};
error.name = 'ValidationException'; error.name = 'ValidationException';
error.violations = response.violations.map((violation) => `${violation.title}`); error.violations = response.violations.map((violation) => `${violation.title}`);
error.propertyPaths = response.violations.map((violation) => `${violation.propertyPath}`);
return error; return error;
} }

View File

@ -91,6 +91,7 @@ import Modal from 'ChillMainAssets/vuejs/_components/Modal';
import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue'; import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
import PersonSuggestion from './AddPersons/PersonSuggestion'; import PersonSuggestion from './AddPersons/PersonSuggestion';
import { searchEntities } from 'ChillPersonAssets/vuejs/_api/AddPersons'; import { searchEntities } from 'ChillPersonAssets/vuejs/_api/AddPersons';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
import { postPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly"; import { postPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly";
import { postThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly"; import { postThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly";
@ -267,13 +268,20 @@ export default {
saveFormOnTheFly({ type, data }) { saveFormOnTheFly({ type, data }) {
console.log('saveFormOnTheFly from addPersons, type', type, ', data', data); console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
if (type === 'person') { if (type === 'person') {
console.log('type person with', data); makeFetch('POST', '/api/1.0/person/person.json', data)
postPerson(data) .then(response => {
.then(person => new Promise((resolve, reject) => { this.newPriorSuggestion(response);
console.log('onthefly create: post person', person); })
this.newPriorSuggestion(person); .catch((error) => {
resolve(); //commit('catchError', error);
})); if (error.name === 'ValidationException') {
for (let e of error.propertyPaths) {
this.$toast.open({message: `${e}` }); //TODO better exploit violations messages
}
} else {
this.$toast.open({message: 'An error occurred'});
}
})
} }
else if (type === 'thirdparty') { else if (type === 'thirdparty') {
console.log('type thirdparty with', data); console.log('type thirdparty with', data);