mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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':
|
case 'create':
|
||||||
return postRelationship(this.modal.data)
|
return postRelationship(this.modal.data)
|
||||||
.then(relationship => new Promise(resolve => {
|
.then(relationship => new Promise(resolve => {
|
||||||
//console.log('post relationship response', relationship)
|
//console.log('post relationship response', relationship)
|
||||||
this.$store.dispatch('addLinkFromRelationship', relationship)
|
this.$store.dispatch('addLinkFromRelationship', relationship)
|
||||||
this.modal.showModal = false
|
this.modal.showModal = false
|
||||||
this.resetForm()
|
this.resetForm()
|
||||||
this.forceUpdateComponent()
|
this.forceUpdateComponent()
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
.catch()
|
.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':
|
case 'edit':
|
||||||
return patchRelationship(this.modal.data)
|
return patchRelationship(this.modal.data)
|
||||||
|
@ -1,50 +1,5 @@
|
|||||||
import { splitId } from './vis-network'
|
import { splitId } from './vis-network';
|
||||||
|
import {makeFetch} from 'ChillMainAssets/lib/api/apiMethods.js';
|
||||||
/**
|
|
||||||
* @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'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function getFetch
|
* @function getFetch
|
||||||
@ -136,7 +91,7 @@ const getRelationsList = () => {
|
|||||||
* @returns {Promise<Response>}
|
* @returns {Promise<Response>}
|
||||||
*/
|
*/
|
||||||
const postRelationship = (relationship) => {
|
const postRelationship = (relationship) => {
|
||||||
//console.log(relationship)
|
//console.log(relationship);
|
||||||
return postFetch(
|
return postFetch(
|
||||||
`/api/1.0/relations/relationship.json`,
|
`/api/1.0/relations/relationship.json`,
|
||||||
{
|
{
|
||||||
|
@ -3,8 +3,10 @@ import { store } from "./store.js"
|
|||||||
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'
|
||||||
import { visMessages } from './i18n'
|
import { visMessages } from './i18n'
|
||||||
import App from './App.vue'
|
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 i18n = _createI18n(visMessages)
|
||||||
const container = document.getElementById('relationship-graph')
|
const container = document.getElementById('relationship-graph')
|
||||||
@ -25,5 +27,11 @@ const app = createApp({
|
|||||||
})
|
})
|
||||||
.use(store)
|
.use(store)
|
||||||
.use(i18n)
|
.use(i18n)
|
||||||
|
.use(VueToast, {
|
||||||
|
position: "bottom-right",
|
||||||
|
type: "error",
|
||||||
|
duration: 5000,
|
||||||
|
dismissible: true
|
||||||
|
})
|
||||||
.component('app', App)
|
.component('app', App)
|
||||||
.mount('#relationship-graph')
|
.mount('#relationship-graph')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user