visgraph: post, patch and delete relationship link works!

This commit is contained in:
2021-11-09 19:54:01 +01:00
parent d6da6a5d9d
commit b392bc9e65
4 changed files with 78 additions and 39 deletions

View File

@@ -1,3 +1,5 @@
import { splitId } from './vis-network'
/**
* @function makeFetch
* @param method
@@ -130,21 +132,19 @@ const getRelationsList = () => {
/**
* @function postRelationship
* @param fromPerson
* @param toPerson
* @param relation
* @param reverse
* @param relationship
* @returns {Promise<Response>}
*/
const postRelationship = (fromPerson, toPerson, relation, reverse) => {
const postRelationship = (relationship) => {
console.log(relationship)
return postFetch(
`/api/1.0/relations/relationship.json`,
{
type: 'relationship',
fromPerson: { type: 'person', id: fromPerson._id },
toPerson: { type: 'person', id: toPerson._id },
relation: { type: 'relation', id: relation.id },
reverse: reverse
fromPerson: { type: 'person', id: splitId(relationship.from, 'id') },
toPerson: { type: 'person', id: splitId(relationship.to, 'id') },
relation: { type: 'relation', id: relationship.relation.id },
reverse: relationship.reverse
}
)
}
@@ -156,12 +156,14 @@ const postRelationship = (fromPerson, toPerson, relation, reverse) => {
*/
const patchRelationship = (relationship) => {
console.log(relationship)
let linkType = splitId(relationship.id, 'link')
let id = splitId(linkType, 'id')
return patchFetch(
`/api/1.0/relations/relationship/${relationship.id}.json`,
`/api/1.0/relations/relationship/${id}.json`,
{
type: 'relationship',
fromPerson: { type: 'person', id: relationship.fromPerson.id },
toPerson: { type: 'person', id: relationship.toPerson.id },
fromPerson: { type: 'person', id: splitId(relationship.from, 'id') },
toPerson: { type: 'person', id: splitId(relationship.to, 'id') },
relation: { type: 'relation', id: relationship.relation.id },
reverse: relationship.reverse
}
@@ -174,8 +176,11 @@ const patchRelationship = (relationship) => {
* @returns {Promise<Response>}
*/
const deleteRelationship = (relationship) => {
console.log(relationship)
let linkType = splitId(relationship.id, 'link')
let id = splitId(linkType, 'id')
return deleteFetch(
`/api/1.0/relations/relationship/${relationship.id}.json`
`/api/1.0/relations/relationship/${id}.json`
)
}