InstalmentOffer.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. import { InstalmentOffer, InstalmentOfferList } from 'src/models/InstalmentOffer.js'
  4. export default class InstalmentOfferAPI extends APIRepository {
  5. constructor() {
  6. super('invoice', appApi)
  7. this.APIAdresses = {
  8. base: '/accounting/instalment_offers',
  9. byId: (id) => '/accounting/instalment_offers/' + id,
  10. accept: (id) => '/accounting/instalment_offers/' + id + '/accept',
  11. reject: (id) => '/accounting/instalment_offers/' + id + '/reject'
  12. }
  13. this.CacheList = {
  14. base: this.name + this.APIAdresses.base
  15. }
  16. this.restUrl = (id) => this.APIAdresses.base + '/' + id
  17. /* Setting the callback functions for the CRUD operations. */
  18. this.setCrudCallbacks({
  19. get: (response) => { return new InstalmentOffer(response.data) },
  20. post: (response) => { return new InstalmentOffer(response.data) },
  21. put: (response) => { return new InstalmentOffer(response.data) },
  22. delete: (response) => { return response.data }
  23. })
  24. }
  25. index(data) {
  26. return this.sendRequest({
  27. apiMethod: 'get',
  28. api: this.api,
  29. request: this.APIAdresses.base,
  30. data: this.getNormalizedSendData({
  31. page: 1 // Number
  32. }, data),
  33. resolveCallback: (response) => {
  34. const paginate = response.data
  35. const results = response.data.results
  36. delete paginate.results
  37. return {
  38. list: new InstalmentOfferList(results),
  39. paginate
  40. // {
  41. // "count": 1,
  42. // "num_pages": 1,
  43. // "per_page": 10,
  44. // "current": 1,
  45. // "next": null,
  46. // "previous": null,
  47. // }
  48. }
  49. },
  50. rejectCallback: (error) => {
  51. return error
  52. }
  53. })
  54. }
  55. accept(id) {
  56. return this.sendRequest({
  57. apiMethod: 'put',
  58. api: this.api,
  59. request: this.APIAdresses.accept(id),
  60. resolveCallback: (response) => {
  61. return response.data
  62. },
  63. rejectCallback: (error) => {
  64. return error
  65. }
  66. })
  67. }
  68. reject(id) {
  69. return this.sendRequest({
  70. apiMethod: 'put',
  71. api: this.api,
  72. request: this.APIAdresses.reject(id),
  73. resolveCallback: (response) => {
  74. return response.data
  75. },
  76. rejectCallback: (error) => {
  77. return error
  78. }
  79. })
  80. }
  81. }