mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
person: add validation on relationship between person
This commit is contained in:
parent
07ea2b771c
commit
5acd49357e
@ -472,15 +472,25 @@ export default {
|
||||
|
||||
case 'create':
|
||||
return postRelationship(this.modal.data)
|
||||
.then(relationship => new Promise(resolve => {
|
||||
//console.log('post relationship response', relationship)
|
||||
this.$store.dispatch('addLinkFromRelationship', relationship)
|
||||
this.modal.showModal = false
|
||||
this.resetForm()
|
||||
this.forceUpdateComponent()
|
||||
resolve()
|
||||
}))
|
||||
.catch()
|
||||
.then(relationship => new Promise(resolve => {
|
||||
//console.log('post relationship response', relationship)
|
||||
this.$store.dispatch('addLinkFromRelationship', relationship)
|
||||
this.modal.showModal = false
|
||||
this.resetForm()
|
||||
this.forceUpdateComponent()
|
||||
resolve()
|
||||
}))
|
||||
.catch( error => {
|
||||
if (error.name === 'ValidationException') {
|
||||
for (let v of error.violations) {
|
||||
this.$toast.open({message: v });
|
||||
console.log(v)
|
||||
}
|
||||
} else {
|
||||
this.$toast.open({message: 'An error occurred'});
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
case 'edit':
|
||||
return patchRelationship(this.modal.data)
|
||||
|
@ -1,50 +1,5 @@
|
||||
import { splitId } from './vis-network'
|
||||
|
||||
/**
|
||||
* @function makeFetch
|
||||
* @param method
|
||||
* @param url
|
||||
* @param body
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const makeFetch = (method, url, body) => {
|
||||
return fetch(url, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: (body !== null) ? JSON.stringify(body) : null
|
||||
})
|
||||
.then(response => {
|
||||
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
if (response.status === 422) {
|
||||
return response.json().then(violations => {
|
||||
throw ValidationException(violations)
|
||||
});
|
||||
}
|
||||
|
||||
throw {
|
||||
msg: 'Error while updating AccompanyingPeriod Course.',
|
||||
sta: response.status,
|
||||
txt: response.statusText,
|
||||
err: new Error(),
|
||||
body: response.body
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param violations
|
||||
* @constructor
|
||||
*/
|
||||
const ValidationException = (violations) => {
|
||||
this.violations = violations
|
||||
this.name = 'ValidationException'
|
||||
}
|
||||
import { splitId } from './vis-network';
|
||||
import {makeFetch} from 'ChillMainAssets/lib/api/apiMethods.js';
|
||||
|
||||
/**
|
||||
* @function getFetch
|
||||
@ -136,7 +91,7 @@ const getRelationsList = () => {
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const postRelationship = (relationship) => {
|
||||
//console.log(relationship)
|
||||
//console.log(relationship);
|
||||
return postFetch(
|
||||
`/api/1.0/relations/relationship.json`,
|
||||
{
|
||||
|
@ -3,8 +3,10 @@ import { store } from "./store.js"
|
||||
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
||||
import { visMessages } from './i18n'
|
||||
import App from './App.vue'
|
||||
import VueToast from 'vue-toast-notification';
|
||||
import 'vue-toast-notification/dist/theme-sugar.css';
|
||||
|
||||
import './vis-network'
|
||||
import './vis-network';
|
||||
|
||||
const i18n = _createI18n(visMessages)
|
||||
const container = document.getElementById('relationship-graph')
|
||||
@ -25,5 +27,11 @@ const app = createApp({
|
||||
})
|
||||
.use(store)
|
||||
.use(i18n)
|
||||
.use(VueToast, {
|
||||
position: "bottom-right",
|
||||
type: "error",
|
||||
duration: 5000,
|
||||
dismissible: true
|
||||
})
|
||||
.component('app', App)
|
||||
.mount('#relationship-graph')
|
||||
|
Loading…
x
Reference in New Issue
Block a user