Session.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. import { Session, SessionList } from 'src/models/Session.js'
  4. export default class SessionAPI extends APIRepository {
  5. constructor() {
  6. super('Session', appApi, '/lma/categories', Session)
  7. this.APIAdresses = {
  8. base: '/lma/sessions',
  9. attendanceSheets: '/lma/sessions/attendance_sheets',
  10. byId: (id) => '/lma/sessions/' + id,
  11. sessionAndCurrentUserAttendanceSheet: (id) => '/lma/sessions/' + id + '/session_and_current_user_attendance_sheet',
  12. sessionAndCurrentUserAttendanceSheetOfUser: (sessionId, userId) => '/lma/sessions/' + sessionId + '/session_and_owner_user_attendance_sheet/' + userId
  13. }
  14. this.CacheList = {
  15. base: this.name + this.APIAdresses.base,
  16. byId: (id) => this.name + this.APIAdresses.byId(id)
  17. }
  18. }
  19. index(data) {
  20. return this.sendRequest({
  21. apiMethod: 'get',
  22. api: this.api,
  23. request: this.APIAdresses.base,
  24. data: this.getNormalizedSendData({
  25. category: null, // Number
  26. classroom: null, // Number
  27. per_page: 10, // Number
  28. page: 1 // Number
  29. }, data),
  30. resolveCallback: (response) => {
  31. const paginate = response.data
  32. const results = response.data.results
  33. delete paginate.results
  34. return {
  35. list: new SessionList(results),
  36. paginate
  37. // {
  38. // "count": 1,
  39. // "num_pages": 1,
  40. // "per_page": 10,
  41. // "current": 1,
  42. // "next": null,
  43. // "previous": null,
  44. // }
  45. }
  46. },
  47. rejectCallback: (error) => {
  48. return error
  49. }
  50. })
  51. }
  52. create (data) {
  53. return this.sendRequest({
  54. apiMethod: 'post',
  55. api: this.api,
  56. request: this.APIAdresses.base,
  57. data: this.getNormalizedSendData({
  58. title: null, // String
  59. classroom: null, // Number
  60. unit: null // Number
  61. }, data),
  62. resolveCallback: (response) => {
  63. return new Session(response.data)
  64. },
  65. rejectCallback: (error) => {
  66. return error
  67. }
  68. })
  69. }
  70. get (id) {
  71. return this.sendRequest({
  72. apiMethod: 'get',
  73. api: this.api,
  74. request: this.APIAdresses.byId(id),
  75. resolveCallback: (response) => {
  76. return new Session(response.data)
  77. },
  78. rejectCallback: (error) => {
  79. return error
  80. }
  81. })
  82. }
  83. }