ContentTopic.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. import { ContentTopic, ContentTopicList } from 'src/models/ContentTopic.js'
  4. export default class ContentTopicAPI extends APIRepository {
  5. constructor() {
  6. super('content-topic', appApi)
  7. this.APIAdresses = {
  8. base: '/cma/topics',
  9. byId: (id) => '/cma/topics/' + id
  10. }
  11. this.CacheList = {
  12. base: this.name + this.APIAdresses.base
  13. }
  14. this.restUrl = (id) => this.APIAdresses.base + '/' + id
  15. /* Setting the callback functions for the CRUD operations. */
  16. this.setCrudCallbacks({
  17. get: (response) => { return new ContentTopic(response.data) },
  18. post: (response) => { return new ContentTopic(response.data) },
  19. put: (response) => { return new ContentTopic(response.data) },
  20. delete: (response) => { return response.data }
  21. })
  22. }
  23. index(data) {
  24. return this.sendRequest({
  25. apiMethod: 'get',
  26. api: this.api,
  27. request: this.APIAdresses.base,
  28. data: this.getNormalizedSendData({
  29. content: null, // Number
  30. creator: null, // Number
  31. category: null, // Number
  32. tile: null, // String
  33. category__parent__parent: null, // Number
  34. category__in: null, // Number[]
  35. hashtags__id__in: null, // Number[]
  36. hashtags__in: null, // Number[]
  37. per_page: 10, // Number
  38. page: 1 // Number
  39. }, data),
  40. resolveCallback: (response) => {
  41. const paginate = response.data
  42. const results = response.data.results
  43. delete paginate.results
  44. return {
  45. list: new ContentTopicList(results),
  46. paginate
  47. // {
  48. // "count": 1,
  49. // "num_pages": 1,
  50. // "per_page": 10,
  51. // "current": 1,
  52. // "next": null,
  53. // "previous": null,
  54. // }
  55. }
  56. },
  57. rejectCallback: (error) => {
  58. return error
  59. }
  60. })
  61. }
  62. }