Session.js 1.8 KB

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