Add HTTP client wrapper and upgrade Axios to v1 (#594)

* refactor: add HTTP client wrapper and upgrade axios to v1

Introduce a thin HTTP wrapper (resources/scripts/http) that centralizes
axios configuration, interceptors, and auth header injection. All 43
files now import from the wrapper instead of axios directly, making
future library swaps a single-file change. Upgrade axios from 0.30.0
to 1.14.0.

* fix: restore window.Ls assignment removed during axios refactor

company.js uses window.Ls.set() to persist selected company,
which broke after the axios plugin (that set window.Ls) was deleted.
This commit is contained in:
Darko Gjorgjijoski
2026-04-02 15:08:23 +02:00
committed by GitHub
parent a38f09cf7b
commit 691178857f
46 changed files with 637 additions and 394 deletions

View File

@@ -1,4 +1,4 @@
import axios from 'axios'
import http from '@/scripts/http'
import { defineStore } from 'pinia'
import { handleError } from '@/scripts/helpers/error-handling'
import { useNotificationStore } from '@/scripts/stores/notification'
@@ -38,7 +38,7 @@ export const useExpenseStore = (useWindow = false) => {
fetchExpenses(params) {
return new Promise((resolve, reject) => {
axios
http
.get(`/api/v1/expenses`, { params })
.then((response) => {
this.expenses = response.data.data
@@ -54,7 +54,7 @@ export const useExpenseStore = (useWindow = false) => {
fetchExpense(id) {
return new Promise((resolve, reject) => {
axios
http
.get(`/api/v1/expenses/${id}`)
.then((response) => {
if (response.data) {
@@ -97,7 +97,7 @@ export const useExpenseStore = (useWindow = false) => {
const formData = utils.toFormData(data)
return new Promise((resolve, reject) => {
axios
http
.post('/api/v1/expenses', formData)
.then((response) => {
this.expenses.push(response.data)
@@ -127,7 +127,7 @@ export const useExpenseStore = (useWindow = false) => {
formData.append('is_attachment_receipt_removed', isAttachmentReceiptRemoved)
return new Promise((resolve) => {
axios.post(`/api/v1/expenses/${id}`, formData).then((response) => {
http.post(`/api/v1/expenses/${id}`, formData).then((response) => {
let pos = this.expenses.findIndex(
(expense) => expense.id === response.data.id
)
@@ -175,7 +175,7 @@ export const useExpenseStore = (useWindow = false) => {
const notificationStore = useNotificationStore()
return new Promise((resolve, reject) => {
axios
http
.post(`/api/v1/expenses/delete`, id)
.then((response) => {
let index = this.expenses.findIndex(
@@ -200,7 +200,7 @@ export const useExpenseStore = (useWindow = false) => {
const notificationStore = useNotificationStore()
return new Promise((resolve, reject) => {
axios
http
.post(`/api/v1/expenses/delete`, { ids: this.selectedExpenses })
.then((response) => {
this.selectedExpenses.forEach((expense) => {
@@ -223,7 +223,7 @@ export const useExpenseStore = (useWindow = false) => {
},
fetchPaymentModes(params) {
return new Promise((resolve, reject) => {
axios
http
.get(`/api/v1/payment-methods`, { params })
.then((response) => {
this.paymentModes = response.data.data