catchError mutation

This commit is contained in:
Mathieu Jaumotte 2021-05-17 13:27:53 +02:00
parent 55264da092
commit 2aa13dceff

View File

@ -23,6 +23,9 @@ let initPromise = getAccompanyingCourse(id)
getters: { getters: {
}, },
mutations: { mutations: {
catchError(state, error) {
state.errorMsg.push(error);
},
removeParticipation(state, participation) { removeParticipation(state, participation) {
//console.log('### mutation: remove participation', participation.id); //console.log('### mutation: remove participation', participation.id);
state.accompanyingCourse.participations = state.accompanyingCourse.participations.filter(element => element !== participation); state.accompanyingCourse.participations = state.accompanyingCourse.participations.filter(element => element !== participation);
@ -73,102 +76,75 @@ let initPromise = getAccompanyingCourse(id)
// fetch DELETE request... // fetch DELETE request...
}, },
closeParticipation({ commit }, payload) { closeParticipation({ commit }, payload) {
console.log('## action: fetch delete participation: payload', payload); //console.log('## action: fetch delete participation: payload', payload);
postParticipation(id, payload.person, 'DELETE') postParticipation(id, payload.person, 'DELETE')
.then(participation => new Promise((resolve, reject) => { .then(participation => new Promise((resolve, reject) => {
commit('closeParticipation', { participation, payload }); commit('closeParticipation', { participation, payload });
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
addParticipation({ commit }, payload) { addParticipation({ commit }, payload) {
console.log('## action: fetch post participation (select item): payload', payload); //console.log('## action: fetch post participation (select item): payload', payload);
postParticipation(id, payload.result, 'POST') postParticipation(id, payload.result, 'POST')
.then(participation => new Promise((resolve, reject) => { .then(participation => new Promise((resolve, reject) => {
commit('addParticipation', participation); commit('addParticipation', participation);
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
removeRequestor({ commit, dispatch }) { removeRequestor({ commit, dispatch }) {
console.log('## action: fetch delete requestor'); //console.log('## action: fetch delete requestor');
postRequestor(id, null, 'DELETE') postRequestor(id, null, 'DELETE')
.then(requestor => new Promise((resolve, reject) => { .then(requestor => new Promise((resolve, reject) => {
commit('removeRequestor'); commit('removeRequestor');
dispatch('requestorIsAnonymous', false); dispatch('requestorIsAnonymous', false);
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
addRequestor({ commit }, payload) { addRequestor({ commit }, payload) {
console.log('## action: fetch post requestor: payload', payload); //console.log('## action: fetch post requestor: payload', payload);
postRequestor(id, payload.result, 'POST') postRequestor(id, payload.result, 'POST')
.then(requestor => new Promise((resolve, reject) => { .then(requestor => new Promise((resolve, reject) => {
commit('addRequestor', requestor); commit('addRequestor', requestor);
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
requestorIsAnonymous({ commit }, payload) { requestorIsAnonymous({ commit }, payload) {
console.log('## action: fetch patch AccompanyingCourse: payload', payload); //console.log('## action: fetch patch AccompanyingCourse: payload', payload);
patchAccompanyingCourse(id, { type: "accompanying_period", requestorAnonymous: payload }) patchAccompanyingCourse(id, { type: "accompanying_period", requestorAnonymous: payload })
.then(course => new Promise((resolve, reject) => { .then(course => new Promise((resolve, reject) => {
commit('requestorIsAnonymous', course.requestorAnonymous) commit('requestorIsAnonymous', course.requestorAnonymous)
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
removeResource({ commit }, payload) { removeResource({ commit }, payload) {
console.log('## action: fetch postResource: payload', payload); //console.log('## action: fetch postResource: payload', payload);
postResource(id, payload, 'DELETE') postResource(id, payload, 'DELETE')
.then(resource => new Promise((resolve, reject) => { .then(resource => new Promise((resolve, reject) => {
commit('removeResource', payload) // mieux un retour de l'objet ! commit('removeResource', payload) // mieux un retour de l'objet !
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
addResource({ commit }, payload) { addResource({ commit }, payload) {
console.log('## action: fetch postResource: payload', payload); //console.log('## action: fetch postResource: payload', payload);
postResource(id, payload.result, 'POST') postResource(id, payload.result, 'POST')
.then(resource => new Promise((resolve, reject) => { .then(resource => new Promise((resolve, reject) => {
commit('addResource', resource) commit('addResource', resource)
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
toggleEmergency({ commit }, payload) { toggleEmergency({ commit }, payload) {
patchAccompanyingCourse(id, { type: "accompanying_period", emergency: payload }) patchAccompanyingCourse(id, { type: "accompanying_period", emergency: payload })
.then(course => new Promise((resolve, reject) => { .then(course => new Promise((resolve, reject) => {
commit('toggleEmergency', course.emergency); commit('toggleEmergency', course.emergency);
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
}, },
toggleConfidential({ commit }, payload) { toggleConfidential({ commit }, payload) {
patchAccompanyingCourse(id, { type: "accompanying_period", confidential: payload }) patchAccompanyingCourse(id, { type: "accompanying_period", confidential: payload })
.then(course => new Promise((resolve, reject) => { .then(course => new Promise((resolve, reject) => {
commit('toggleConfidential', course.confidential); commit('toggleConfidential', course.confidential);
resolve(); resolve();
})) })).catch((error) => { commit('catchError', error) });
.catch((error) => {
state.errorMsg.push(error.message);
});
} }
} }
}); });