Transaction.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { appApi } from 'src/boot/axios.js'
  2. import APIRepository from '../classes/APIRepository.js'
  3. import { Transaction, TransactionList } from 'src/models/Transaction.js'
  4. export default class TransactionAPI extends APIRepository {
  5. constructor() {
  6. super('invoice', appApi)
  7. this.APIAdresses = {
  8. base: '/accounting/transactions',
  9. byId: (id) => '/accounting/transactions/' + 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 Transaction(response.data) },
  18. post: (response) => { return new Transaction(response.data) },
  19. put: (response) => { return new Transaction(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. page: 1 // Number
  30. }, data),
  31. resolveCallback: (response) => {
  32. const paginate = response.data
  33. const results = response.data.results
  34. delete paginate.results
  35. return {
  36. list: new TransactionList(results),
  37. paginate
  38. // {
  39. // "count": 1,
  40. // "num_pages": 1,
  41. // "per_page": 10,
  42. // "current": 1,
  43. // "next": null,
  44. // "previous": null,
  45. // }
  46. }
  47. },
  48. rejectCallback: (error) => {
  49. return error
  50. }
  51. })
  52. }
  53. }