visgraph: prepare PATCH relationship when submitting (wip)

This commit is contained in:
Mathieu Jaumotte 2021-11-03 16:46:27 +01:00
parent 2099edefc5
commit adac384279
2 changed files with 62 additions and 13 deletions

View File

@ -305,8 +305,10 @@ export default {
}, },
submitRelationship() { submitRelationship() {
console.log('submitRelationship') console.log('submitRelationship with action', this.modal.action)
if (this.modal.action !== 'delete') { switch (this.modal.action) {
case 'create':
return postRelationship( return postRelationship(
this.getPerson(this.modal.data.from), this.getPerson(this.modal.data.to), this.relation, this.reverse this.getPerson(this.modal.data.from), this.getPerson(this.modal.data.to), this.relation, this.reverse
) )
@ -318,6 +320,28 @@ export default {
resolve() resolve()
})) }))
.catch() .catch()
case 'edit':
/// TODO
// récupérer la relationship,
// la modifier,
// patcher en reconstruisant le body,
// récupérer la réponse,
// mettre le link (edge) à jour
return patchRelationship(relationship)
.then(response => new Promise(resolve => {
console.log('patch response', response)
this.$store.dispatch('updateLinkFromRelationship', adapt2vis(response))
this.modal.showModal = false
this.resetForm()
resolve()
}))
.catch()
case 'delete':
break
default:
throw "undefined action"
} }
} }
} }

View File

@ -139,10 +139,35 @@ const postRelationship = (fromPerson, toPerson, relation, reverse) => {
) )
} }
/**
* @function patchRelationship
* @param relationship
* @returns {Promise<Response>}
*/
const patchRelationship = (relationship) => {
return patchFetch(
`/api/1.0/relations/relationship/${relationship._id}.json`,
{
type: 'relationship',
fromPerson: { type: 'person',
id: fromPerson._id
},
toPerson: { type: 'person',
id: toPerson._id
},
relation: { type: 'relation',
id: relation.id
},
reverse: reverse
}
)
}
export { export {
getHouseholdByPerson, getHouseholdByPerson,
getCoursesByPerson, getCoursesByPerson,
getRelationshipsByPerson, getRelationshipsByPerson,
getRelationsList, getRelationsList,
postRelationship, postRelationship,
patchRelationship
} }