Session.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  13. this.CacheList = {
  14. base: this.name + this.APIAdresses.base,
  15. byId: (id) => this.name + this.APIAdresses.byId(id)
  16. }
  17. }
  18. index(data) {
  19. return this.sendRequest({
  20. apiMethod: 'get',
  21. api: this.api,
  22. request: this.APIAdresses.base,
  23. data: this.getNormalizedSendData({
  24. category: null, // Number
  25. classroom: null, // Number
  26. per_page: 10, // Number
  27. page: 1 // Number
  28. }, data),
  29. resolveCallback: (response) => {
  30. const paginate = response.data
  31. const results = response.data.results
  32. delete paginate.results
  33. return {
  34. list: new SessionList(results),
  35. paginate
  36. // {
  37. // "count": 1,
  38. // "num_pages": 1,
  39. // "per_page": 10,
  40. // "current": 1,
  41. // "next": null,
  42. // "previous": null,
  43. // }
  44. }
  45. },
  46. rejectCallback: (error) => {
  47. return error
  48. }
  49. })
  50. }
  51. create (data) {
  52. return this.sendRequest({
  53. apiMethod: 'post',
  54. api: this.api,
  55. request: this.APIAdresses.base,
  56. data: this.getNormalizedSendData({
  57. title: null, // String
  58. classroom: null, // Number
  59. unit: null // Number
  60. }, data),
  61. resolveCallback: (response) => {
  62. return new Session(response.data)
  63. },
  64. rejectCallback: (error) => {
  65. return error
  66. }
  67. })
  68. }
  69. get (id) {
  70. return this.sendRequest({
  71. apiMethod: 'get',
  72. api: this.api,
  73. request: this.APIAdresses.byId(id),
  74. resolveCallback: (response) => {
  75. return new Session(response.data)
  76. },
  77. rejectCallback: (error) => {
  78. return error
  79. }
  80. })
  81. }
  82. }