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