person: add validation on relationship between person

This commit is contained in:
nobohan
2022-04-22 17:22:56 +02:00
parent 07ea2b771c
commit 5acd49357e
3 changed files with 31 additions and 58 deletions

View File

@@ -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`,
{