course.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. updateCourseValue({commit}, {value, field}) {
  46. commit('setCourseValue', {value, field})
  47. }
  48. }
  49. export const mutations = {
  50. setCourses(state, courses) {
  51. state.items = courses
  52. },
  53. setCourse(state, course) {
  54. state.item = course
  55. },
  56. addLine(state, field) {
  57. console.log('course.js mutations call addLine params > ', field)
  58. state.item[field].push({value: ''})
  59. console.log('course.js mutations done addLine params')
  60. },
  61. removeLine(state, {field, index}) {
  62. console.log('course.js mutations call removeLine params > ', field, ':', index)
  63. state.item[field].splice(index, 1)
  64. console.log('course.js mutations done removeLine params')
  65. },
  66. setLineValue(state, {index, value, field}) {
  67. console.log('course.js mutations call setLineValue params > ', {index, value, field})
  68. state.item[field][index].value = value
  69. console.log('course.js mutations done setLineValue params')
  70. },
  71. setCourseValue(state, {value, field}){
  72. state.item[field] = value
  73. }
  74. }