add and remove requestor functions

This commit is contained in:
2021-05-10 18:46:21 +02:00
parent 4e31b3e424
commit f7c08f02c2
3 changed files with 83 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
import 'es6-promise/auto';
import { createStore } from 'vuex';
import { getAccompanyingCourse, postParticipation } from '../api';
import { getAccompanyingCourse, postParticipation, postRequestor } from '../api';
const debug = process.env.NODE_ENV !== 'production';
const id = window.accompanyingCourseId;
@@ -34,9 +34,13 @@ let initPromise = getAccompanyingCourse(id)
//console.log('### mutation: add participation', participation);
state.accompanyingCourse.participations.push(participation);
},
removeRequestor(state) {
state.accompanyingCourse.requestor = null;
},
addRequestor(state, requestor) {
console.log(requestor);
},
state.accompanyingCourse.requestor = requestor;
}
},
actions: {
removeParticipation({ commit }, payload) {
@@ -58,7 +62,16 @@ let initPromise = getAccompanyingCourse(id)
postParticipation(id, payload.result.person_id, 'POST')
.then(participation => new Promise((resolve, reject) => {
commit('addParticipation', participation);
//addPersons.commit('resetState', payload);
resolve();
}))
.catch((error) => {
state.errorMsg.push(error.message);
});
},
removeRequestor({ commit }) {
postRequestor(id, null, 'DELETE')
.then(requestor => new Promise((resolve, reject) => {
commit('removeRequestor');
resolve();
}))
.catch((error) => {
@@ -67,7 +80,14 @@ let initPromise = getAccompanyingCourse(id)
},
addRequestor({ commit }, payload) {
console.log(payload);
commit('addRequestor', payload);
postRequestor(id, payload, 'POST')
.then(requestor => new Promise((resolve, reject) => {
commit('addRequestor', requestor);
resolve();
}))
.catch((error) => {
state.errorMsg.push(error.message);
});
}
}
});