mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 20:21:10 -04:00
v6 update
This commit is contained in:
62
resources/scripts/customer/stores/invoice.js
Normal file
62
resources/scripts/customer/stores/invoice.js
Normal file
@ -0,0 +1,62 @@
|
||||
import { handleError } from '@/scripts/customer/helpers/error-handling'
|
||||
const { defineStore } = window.pinia
|
||||
import axios from 'axios'
|
||||
export const useInvoiceStore = defineStore({
|
||||
id: 'customerInvoiceStore',
|
||||
state: () => ({
|
||||
totalInvoices: 0,
|
||||
invoices: [],
|
||||
selectedViewInvoice: [],
|
||||
}),
|
||||
|
||||
actions: {
|
||||
fetchInvoices(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/invoices`, { params })
|
||||
.then((response) => {
|
||||
this.invoices = response.data.data
|
||||
this.totalInvoices = response.data.meta.invoiceTotalCount
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
fetchViewInvoice(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/invoices/${params.id}`, {
|
||||
params,
|
||||
})
|
||||
|
||||
.then((response) => {
|
||||
this.selectedViewInvoice = response.data.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
searchInvoice(params, slug) {
|
||||
return new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(`/api/v1/${slug}/customer/invoices`, { params })
|
||||
.then((response) => {
|
||||
this.invoices = response.data
|
||||
resolve(response)
|
||||
})
|
||||
.catch((err) => {
|
||||
handleError(err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user