mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
person: on-the-fly person: first implementation of makeFetch for posting person
This commit is contained in:
parent
15342f85d3
commit
378f3a16fc
@ -86,6 +86,7 @@ const ValidationException = (response) => {
|
||||
const error = {};
|
||||
error.name = 'ValidationException';
|
||||
error.violations = response.violations.map((violation) => `${violation.title}`);
|
||||
error.propertyPaths = response.violations.map((violation) => `${violation.propertyPath}`);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
||||
import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
|
||||
import PersonSuggestion from './AddPersons/PersonSuggestion';
|
||||
import { searchEntities } from 'ChillPersonAssets/vuejs/_api/AddPersons';
|
||||
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
|
||||
import { postPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly";
|
||||
import { postThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly";
|
||||
|
||||
@ -267,13 +268,20 @@ export default {
|
||||
saveFormOnTheFly({ type, data }) {
|
||||
console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
|
||||
if (type === 'person') {
|
||||
console.log('type person with', data);
|
||||
postPerson(data)
|
||||
.then(person => new Promise((resolve, reject) => {
|
||||
console.log('onthefly create: post person', person);
|
||||
this.newPriorSuggestion(person);
|
||||
resolve();
|
||||
}));
|
||||
makeFetch('POST', '/api/1.0/person/person.json', data)
|
||||
.then(response => {
|
||||
this.newPriorSuggestion(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
//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') {
|
||||
console.log('type thirdparty with', data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user