forked from VinokurovVE/tests
axiosInstance config
This commit is contained in:
@ -1,2 +1,4 @@
|
|||||||
VITE_API_URL=
|
VITE_API_AUTH_URL=
|
||||||
VITE_API_AUTH_URL=
|
VITE_API_INFO_URL=
|
||||||
|
VITE_API_FUEL_URL=
|
||||||
|
VITE_API_SERVERS_URL=
|
@ -1,9 +1,7 @@
|
|||||||
import axios, { ResponseType } from 'axios';
|
import axios, { ResponseType } from 'axios';
|
||||||
import { useAuthStore } from '../store/auth';
|
import { useAuthStore } from '../store/auth';
|
||||||
|
|
||||||
const axiosInstance = axios.create({
|
const axiosInstance = axios.create();
|
||||||
baseURL: import.meta.env.VITE_API_INFO_URL,
|
|
||||||
});
|
|
||||||
|
|
||||||
axiosInstance.interceptors.request.use(
|
axiosInstance.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
|
@ -1,11 +1,19 @@
|
|||||||
import { AxiosProgressEvent } from "axios";
|
import { AxiosProgressEvent, AxiosRequestConfig } from "axios";
|
||||||
import axiosInstance from "../http/axiosInstance";
|
import axiosInstance from "../http/axiosInstance";
|
||||||
import { IBank, ICompany, IDepartment, IDocument, IDocumentFolder, IOrganization, IOrganizationBank } from "../interfaces/documents";
|
import { IBank, ICompany, IDepartment, IDocument, IDocumentFolder, IOrganization, IOrganizationBank } from "../interfaces/documents";
|
||||||
|
import { BASE_URL } from "../constants";
|
||||||
|
|
||||||
|
const config: AxiosRequestConfig = {
|
||||||
|
baseURL: BASE_URL.info,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class DocumentService {
|
export default class DocumentService {
|
||||||
// Get Main
|
// Get Main
|
||||||
static async getMain() {
|
static async getMain() {
|
||||||
return await axiosInstance.get(`/info/`)
|
return await axiosInstance.get(`/info/`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Companies
|
// Get Companies
|
||||||
@ -14,23 +22,24 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
limit: limit || 10,
|
limit: limit || 10,
|
||||||
offset: offset || 0
|
offset: offset || 0
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Company
|
// Create Company
|
||||||
static async createCompany(data: ICompany) {
|
static async createCompany(data: ICompany) {
|
||||||
return await axiosInstance.post(`/info/companies/`, data)
|
return await axiosInstance.post(`/info/companies/`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Company
|
// Delete Company
|
||||||
static async deleteCompany(company_id: number) {
|
static async deleteCompany(company_id: number) {
|
||||||
return await axiosInstance.delete(`/info/companies/${company_id}`)
|
return await axiosInstance.delete(`/info/companies/${company_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Company
|
// Update Company
|
||||||
static async updateCompany(company_id: number) {
|
static async updateCompany(company_id: number) {
|
||||||
return await axiosInstance.patch(`/info/companies/${company_id}`)
|
return await axiosInstance.patch(`/info/companies/${company_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Departments
|
// Get Departments
|
||||||
@ -39,29 +48,30 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
limit: limit || 10,
|
limit: limit || 10,
|
||||||
offset: offset || 0
|
offset: offset || 0
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Department
|
// Get Department
|
||||||
static async getDepartment(department_id: number) {
|
static async getDepartment(department_id: number) {
|
||||||
return await axiosInstance.get(`/info/departments/${department_id}`)
|
return await axiosInstance.get(`/info/departments/${department_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Delete Department
|
// Delete Department
|
||||||
static async deleteDepartment(department_id: number) {
|
static async deleteDepartment(department_id: number) {
|
||||||
return await axiosInstance.delete(`/info/departments/${department_id}`)
|
return await axiosInstance.delete(`/info/departments/${department_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Department
|
// Update Department
|
||||||
static async updateDepartment(department_id: number, data: IDepartment) {
|
static async updateDepartment(department_id: number, data: IDepartment) {
|
||||||
return await axiosInstance.patch(`/info/departments/${department_id}`, data)
|
return await axiosInstance.patch(`/info/departments/${department_id}`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Department
|
// Create Department
|
||||||
static async createDepartment(data: IDepartment) {
|
static async createDepartment(data: IDepartment) {
|
||||||
return await axiosInstance.post(`/info/department/`, data)
|
return await axiosInstance.post(`/info/department/`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Documents
|
// Get Documents
|
||||||
@ -70,33 +80,34 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
limit: limit || 10,
|
limit: limit || 10,
|
||||||
offset: offset || 0
|
offset: offset || 0
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Documentfolder
|
// Create Documentfolder
|
||||||
static async createDocumentFolder(data: IDocumentFolder) {
|
static async createDocumentFolder(data: IDocumentFolder) {
|
||||||
return await axiosInstance.post(`/info/document_folder/`, data)
|
return await axiosInstance.post(`/info/document_folder/`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Document
|
// Get Document
|
||||||
static async getDocument(folder_id: number) {
|
static async getDocument(folder_id: number) {
|
||||||
return await axiosInstance.get(`/info/document_folder/${folder_id}`)
|
return await axiosInstance.get(`/info/document_folder/${folder_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Document
|
// Delete Document
|
||||||
static async deleteDocument(folder_id: number) {
|
static async deleteDocument(folder_id: number) {
|
||||||
return await axiosInstance.delete(`/info/document_folder/${folder_id}`)
|
return await axiosInstance.delete(`/info/document_folder/${folder_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Document
|
// Update Document
|
||||||
static async updateDocument(folder_id: number, data: IDocument) {
|
static async updateDocument(folder_id: number, data: IDocument) {
|
||||||
return await axiosInstance.patch(`/info/document_folder/${folder_id}`, data)
|
return await axiosInstance.patch(`/info/document_folder/${folder_id}`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Docs
|
// Get Docs
|
||||||
static async getDocs(folder_id: number) {
|
static async getDocs(folder_id: number) {
|
||||||
return await axiosInstance.get(`/info/documents/${folder_id}`)
|
return await axiosInstance.get(`/info/documents/${folder_id}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload Files
|
// Upload Files
|
||||||
@ -105,7 +116,8 @@ export default class DocumentService {
|
|||||||
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
|
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
|
||||||
const percentCompleted = progressEvent.progress
|
const percentCompleted = progressEvent.progress
|
||||||
setUploadProgress?.(percentCompleted || 0)
|
setUploadProgress?.(percentCompleted || 0)
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +125,7 @@ export default class DocumentService {
|
|||||||
static async downloadDoc(folder_id: number, doc_id: number) {
|
static async downloadDoc(folder_id: number, doc_id: number) {
|
||||||
return await axiosInstance.get(`/info/document/${folder_id}&${doc_id}`, {
|
return await axiosInstance.get(`/info/document/${folder_id}&${doc_id}`, {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,23 +135,24 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
folder_id: folder_id,
|
folder_id: folder_id,
|
||||||
doc_id: doc_id
|
doc_id: doc_id
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert Phones
|
// Convert Phones
|
||||||
static async convertPhones(data: FormData) {
|
static async convertPhones(data: FormData) {
|
||||||
return await axiosInstance.post(`/info/other/phones/`, data)
|
return await axiosInstance.post(`/info/other/phones/`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Budget
|
// Get Budget
|
||||||
static async getBudget() {
|
static async getBudget() {
|
||||||
return await axiosInstance.get(`/info/organization/budget/`)
|
return await axiosInstance.get(`/info/organization/budget/`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Bank
|
// Add Bank
|
||||||
static async addBank(data: IBank) {
|
static async addBank(data: IBank) {
|
||||||
return await axiosInstance.post(`/info/organization/bank`, data)
|
return await axiosInstance.post(`/info/organization/bank`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Bank
|
// Update Bank
|
||||||
@ -147,7 +161,8 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
bank_id: bank_id,
|
bank_id: bank_id,
|
||||||
bank_1c_id: bank_1c_id
|
bank_1c_id: bank_1c_id
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,13 +174,14 @@ export default class DocumentService {
|
|||||||
search: search || null,
|
search: search || null,
|
||||||
limit: limit || 10,
|
limit: limit || 10,
|
||||||
offset: offset || 0
|
offset: offset || 0
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Bank
|
// Get Bank
|
||||||
static async getBank(id_1c: string) {
|
static async getBank(id_1c: string) {
|
||||||
return await axiosInstance.get(`/info/organization/bank/${id_1c}`)
|
return await axiosInstance.get(`/info/organization/bank/${id_1c}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Bank
|
// Delete Bank
|
||||||
@ -174,13 +190,14 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
bank_id: bank_id,
|
bank_id: bank_id,
|
||||||
bank_1c_id: bank_1c_id
|
bank_1c_id: bank_1c_id
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Org
|
// Add Org
|
||||||
static async addOrganization(data: IOrganization) {
|
static async addOrganization(data: IOrganization) {
|
||||||
return await axiosInstance.post(`/info/organization/org/`, data)
|
return await axiosInstance.post(`/info/organization/org/`, data, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Org
|
// Update Org
|
||||||
@ -189,7 +206,8 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
org_id: org_id,
|
org_id: org_id,
|
||||||
org_1c_id: org_1c_id
|
org_1c_id: org_1c_id
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +217,8 @@ export default class DocumentService {
|
|||||||
params: {
|
params: {
|
||||||
org_id: org_id,
|
org_id: org_id,
|
||||||
org_1c_id: org_1c_id
|
org_1c_id: org_1c_id
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,17 +230,18 @@ export default class DocumentService {
|
|||||||
search: search || null,
|
search: search || null,
|
||||||
limit: limit || 10,
|
limit: limit || 10,
|
||||||
offset: offset || 0
|
offset: offset || 0
|
||||||
}
|
},
|
||||||
|
...config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Org
|
// Get Org
|
||||||
static async getOrganization(id_1c: string) {
|
static async getOrganization(id_1c: string) {
|
||||||
return await axiosInstance.get(`/info/organization/org/${id_1c}`)
|
return await axiosInstance.get(`/info/organization/org/${id_1c}`, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Orgbank
|
// Add Orgbank
|
||||||
static async addOrganizationBank(data: IOrganizationBank) {
|
static async addOrganizationBank(data: IOrganizationBank) {
|
||||||
return await axiosInstance.post(`/info/organization/org_bank`, data)
|
return await axiosInstance.post(`/info/organization/org_bank`, data, config)
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user