| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import { appApi } from 'src/boot/axios.js'
- import APIRepository from '../classes/APIRepository.js'
- import { Invoice, InvoiceList } from 'src/models/Invoice.js'
- export default class InvoiceAPI extends APIRepository {
- constructor() {
- super('invoice', appApi)
- this.APIAdresses = {
- base: '/accounting/invoices',
- instalments: '/accounting/instalments',
- byId: (id) => '/accounting/invoices/' + id,
- pay: (id) => '/accounting/invoices/' + id + '/pay'
- }
- this.CacheList = {
- base: this.name + this.APIAdresses.base
- }
- this.restUrl = (id) => this.APIAdresses.base + '/' + id
- /* Setting the callback functions for the CRUD operations. */
- this.setCrudCallbacks({
- get: (response) => { return new Invoice(response.data) },
- post: (response) => { return new Invoice(response.data) },
- put: (response) => { return new Invoice(response.data) },
- delete: (response) => { return response.data }
- })
- }
- index(data) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.base,
- data: this.getNormalizedSendData({
- page: 1 // Number
- }, data),
- resolveCallback: (response) => {
- const paginate = response.data
- const results = response.data.results
- delete paginate.results
- return {
- list: new InvoiceList(results),
- paginate
- // {
- // "count": 1,
- // "num_pages": 1,
- // "per_page": 10,
- // "current": 1,
- // "next": null,
- // "previous": null,
- // }
- }
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- instalments(data) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.base,
- data: this.getNormalizedSendData({
- type: null, // String -> overdue - ...
- page: 1 // Number
- }, data),
- resolveCallback: (response) => {
- const paginate = response.data
- const results = response.data.results
- delete paginate.results
- return {
- list: new InvoiceList(results),
- paginate
- // {
- // "count": 1,
- // "num_pages": 1,
- // "per_page": 10,
- // "current": 1,
- // "next": null,
- // "previous": null,
- // }
- }
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- pay(invoiceId) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.pay(invoiceId),
- resolveCallback: (response) => {
- return response.data.detail // String : message
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- createService (products = []) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.base,
- data: {
- type: 'SERVICE', // String
- products // Array of Object
- },
- resolveCallback: (response) => {
- return new Invoice(response.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- createBasket (basketType, basketId) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.base,
- data: {
- type: basketType.toUpperCase(), // String
- products: [
- {
- product_type: basketType + '_basket',
- product_id: basketId,
- count: 1
- }
- ]
- },
- resolveCallback: (response) => {
- return new Invoice(response.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- create (type, products = []) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.base,
- data: {
- type, // String
- products // Array of Object
- },
- resolveCallback: (response) => {
- return new Invoice(response.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- }
|