From 378f3a16fc34228334cd44b9e7ca618bc7eb72aa Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 10 Jan 2022 18:11:02 +0100 Subject: [PATCH] person: on-the-fly person: first implementation of makeFetch for posting person --- .../Resources/public/lib/api/apiMethods.js | 1 + .../public/vuejs/_components/AddPersons.vue | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js b/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js index 96a95ad93..9697a5d68 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/api/apiMethods.js @@ -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; } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index f118671ed..d5025c6b1 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -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);