course.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. export const state = () => ({
  2. items : [],
  3. item : []
  4. })
  5. export const actions = {
  6. async fetchInstructorCourses({commit}) {
  7. try{
  8. console.log('courses.js actions call fetchInstructorCourses')
  9. const courses = await this.$axios.$get('/api/v1/products/user-products')
  10. console.log('courses.js actions done fetchInstructorCourses')
  11. console.log('courses.js mutations call setCourses')
  12. commit('setCourses', courses)
  13. console.log('courses.js mutations done setCourses')
  14. return courses
  15. }catch(error){
  16. return error
  17. }
  18. },
  19. async createCourse(_, courseData) {
  20. try {
  21. console.log('instructor/course.js actions createCourse call axios.$post->products')
  22. const result = await this.$axios.$post('/api/v1/products', courseData)
  23. console.log('instructor/course.js actions createCourse done axios.$post->products')
  24. } catch (error) {
  25. return error
  26. }
  27. },
  28. async fetchCourseById({commit, state}, courseId){
  29. try {
  30. console.log('instructor/course.js actions fetchCourseById call axios.$get->courseId')
  31. const course = await this.$axios.$get(`/api/v1/products/${courseId}`)
  32. console.log('instructor/course.js actions fetchCourseById done axios.$get->courseId')
  33. console.log('courses.js mutations call setCourse')
  34. commit('setCourse', course)
  35. console.log('courses.js mutations done setCourse')
  36. return state.item
  37. } catch (error) {
  38. return error
  39. }
  40. },
  41. updateLine({commit}, {index, value, field}) {
  42. commit('setLineValue', {index, value, field})
  43. // Surprise commit for next lectures (:
  44. }
  45. }
  46. export const mutations = {
  47. setCourses(state, courses) {
  48. state.items = courses
  49. },
  50. setCourse(state, course) {
  51. state.item = course
  52. },
  53. addLine(state, field) {
  54. console.log('course.js mutations call addLine params > ', field)
  55. state.item[field].push({value: ''})
  56. console.log('course.js mutations done addLine params')
  57. },
  58. removeLine(state, {field, index}) {
  59. console.log('course.js mutations call removeLine params > ', field, ':', index)
  60. state.item[field].splice(index, 1)
  61. console.log('course.js mutations done removeLine params')
  62. },
  63. setLineValue(state, {index, value, field}) {
  64. console.log('course.js mutations call setLineValue params > ', {index, value, field})
  65. state.item[field][index].value = value
  66. console.log('course.js mutations done setLineValue params')
  67. }
  68. }