mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
fetch postParticipation request, catch fetch error, store mutation+action
This commit is contained in:
@@ -4,49 +4,46 @@ import { getAccompanyingCourse, postParticipation } from '../api/accompanyingCou
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
const id = window.accompanyingCourseId;
|
||||
const id = window.accompanyingCourseId; //tmp
|
||||
|
||||
let getDataPromise = getAccompanyingCourse(id)
|
||||
.then(accompanying_course => new Promise((resolve, reject) => {
|
||||
|
||||
const store = createStore({
|
||||
strict: debug,
|
||||
state: {
|
||||
accompanying_course: accompanying_course
|
||||
accompanying_course: accompanying_course,
|
||||
errorMsg: []
|
||||
},
|
||||
getters: {
|
||||
},
|
||||
mutations: {
|
||||
removeParticipation(state, item) {
|
||||
//console.log('remove item', item.id);
|
||||
console.log('remove item', item.id);
|
||||
state.accompanying_course.participations = state.accompanying_course.participations.filter(
|
||||
participation => participation !== item
|
||||
)
|
||||
},
|
||||
addParticipation(state, item) {
|
||||
//console.log('add new item');
|
||||
console.log('add new item');
|
||||
state.accompanying_course.participations.push(item)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addParticipation({ commit }, payload) {
|
||||
console.log('payload', payload);
|
||||
commit('addParticipation', payload);
|
||||
|
||||
postParticipation(id, payload.id).catch((error) => {
|
||||
commit('removeParticipation', payload)
|
||||
state.errorMsg.push(error.message);
|
||||
})
|
||||
// result action ??
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log('store object', store.state.accompanying_course.id);
|
||||
resolve(store);
|
||||
}));
|
||||
|
||||
let postDataPromise = postParticipation(id)
|
||||
.then(participation => new Promise((resolve, reject) => {
|
||||
// get store
|
||||
// use store.actions to post (async way)
|
||||
console.log(store);
|
||||
resolve(store);
|
||||
}));
|
||||
|
||||
/*
|
||||
let allPromises = Promise.all([getDataPromise, postDataPromise])
|
||||
.then((values) => {
|
||||
console.log('all promises values', values);
|
||||
});
|
||||
*/
|
||||
|
||||
export { getDataPromise };
|
||||
|
Reference in New Issue
Block a user