Team.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. export default class TeamAPI extends APIRepository {
  4. constructor() {
  5. super('teams', appApi, '/lma/teams')
  6. this.APIAdresses = {
  7. base: '/lma/teams',
  8. classroomTeamsWithJoinStatus: '/lma/teams/classroom_teams_with_join_status',
  9. myLeadingTeams: '/lma/teams/my_leading_teams',
  10. byId: (id) => '/lma/teams/' + id,
  11. register: (id) => '/lma/teams/' + id + '/register',
  12. registrations: (id) => '/lma/teams/' + id + '/registrations'
  13. }
  14. this.CacheList = {
  15. base: this.name + this.APIAdresses.base,
  16. byId: (id) => this.name + this.APIAdresses.byId(id)
  17. }
  18. }
  19. appendRegistrations (data) {
  20. return this.sendRequest({
  21. apiMethod: 'put',
  22. api: this.api,
  23. request: this.APIAdresses.registrations(data.teamId),
  24. data: {
  25. registrations: data.registrations // array of numbers
  26. },
  27. resolveCallback: (response) => {
  28. return response.data
  29. },
  30. rejectCallback: (error) => {
  31. return error
  32. }
  33. })
  34. }
  35. register (teamId) {
  36. return this.sendRequest({
  37. apiMethod: 'put',
  38. api: this.api,
  39. request: this.APIAdresses.register(teamId),
  40. resolveCallback: (response) => {
  41. return response.data
  42. },
  43. rejectCallback: (error) => {
  44. return error
  45. }
  46. })
  47. }
  48. }