Session.js 1.9 KB

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