Registration.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. import { Registration, RegistrationList } from 'src/models/Registration.js'
  4. export default class RegistrationAPI extends APIRepository {
  5. constructor() {
  6. super('registrations', appApi, '/lma/registrations', Registration)
  7. this.APIAdresses = {
  8. base: '/lma/registrations',
  9. exportReport: '/lma/registrations/export_report',
  10. byId: (id) => '/lma/registrations/' + 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. owner: 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 RegistrationList(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. exportReport(data) {
  50. return this.sendRequest({
  51. apiMethod: 'get',
  52. api: this.api,
  53. request: this.APIAdresses.exportReport,
  54. data: this.getNormalizedSendData({
  55. classroom: null, // Number
  56. type: null, // String
  57. status: null // String
  58. }, data),
  59. responseType: 'blob',
  60. resolveCallback: (response) => {
  61. return response.data // xlsxData
  62. },
  63. rejectCallback: (error) => {
  64. return error
  65. }
  66. })
  67. }
  68. }