Browse Source

axiosInstance config

master
cracklesparkle 10 months ago
parent
commit
a3043afa7b
  1. 4
      frontend_reactjs/.env.example
  2. 4
      frontend_reactjs/src/http/axiosInstance.ts
  3. 84
      frontend_reactjs/src/services/DocumentService.ts

4
frontend_reactjs/.env.example

@ -1,2 +1,4 @@
VITE_API_URL=
VITE_API_AUTH_URL=
VITE_API_INFO_URL=
VITE_API_FUEL_URL=
VITE_API_SERVERS_URL=

4
frontend_reactjs/src/http/axiosInstance.ts

@ -1,9 +1,7 @@
import axios, { ResponseType } from 'axios';
import { useAuthStore } from '../store/auth';
const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_API_INFO_URL,
});
const axiosInstance = axios.create();
axiosInstance.interceptors.request.use(
(config) => {

84
frontend_reactjs/src/services/DocumentService.ts

@ -1,11 +1,19 @@
import { AxiosProgressEvent } from "axios";
import { AxiosProgressEvent, AxiosRequestConfig } from "axios";
import axiosInstance from "../http/axiosInstance";
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 {
// Get Main
static async getMain() {
return await axiosInstance.get(`/info/`)
return await axiosInstance.get(`/info/`, config)
}
// Get Companies
@ -14,23 +22,24 @@ export default class DocumentService {
params: {
limit: limit || 10,
offset: offset || 0
}
},
...config
})
}
// Create Company
static async createCompany(data: ICompany) {
return await axiosInstance.post(`/info/companies/`, data)
return await axiosInstance.post(`/info/companies/`, data, config)
}
// Delete Company
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
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
@ -39,29 +48,30 @@ export default class DocumentService {
params: {
limit: limit || 10,
offset: offset || 0
}
},
...config
})
}
// Get Department
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
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
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
static async createDepartment(data: IDepartment) {
return await axiosInstance.post(`/info/department/`, data)
return await axiosInstance.post(`/info/department/`, data, config)
}
// Get Documents
@ -70,33 +80,34 @@ export default class DocumentService {
params: {
limit: limit || 10,
offset: offset || 0
}
},
...config
})
}
// Create Documentfolder
static async createDocumentFolder(data: IDocumentFolder) {
return await axiosInstance.post(`/info/document_folder/`, data)
return await axiosInstance.post(`/info/document_folder/`, data, config)
}
// Get Document
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
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
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
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
@ -105,7 +116,8 @@ export default class DocumentService {
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
const percentCompleted = progressEvent.progress
setUploadProgress?.(percentCompleted || 0)
}
},
...config
})
}
@ -113,6 +125,7 @@ export default class DocumentService {
static async downloadDoc(folder_id: number, doc_id: number) {
return await axiosInstance.get(`/info/document/${folder_id}&${doc_id}`, {
responseType: 'blob',
...config
})
}
@ -122,23 +135,24 @@ export default class DocumentService {
params: {
folder_id: folder_id,
doc_id: doc_id
}
},
...config
})
}
// Convert Phones
static async convertPhones(data: FormData) {
return await axiosInstance.post(`/info/other/phones/`, data)
return await axiosInstance.post(`/info/other/phones/`, data, config)
}
// Get Budget
static async getBudget() {
return await axiosInstance.get(`/info/organization/budget/`)
return await axiosInstance.get(`/info/organization/budget/`, config)
}
// Add Bank
static async addBank(data: IBank) {
return await axiosInstance.post(`/info/organization/bank`, data)
return await axiosInstance.post(`/info/organization/bank`, data, config)
}
// Update Bank
@ -147,7 +161,8 @@ export default class DocumentService {
params: {
bank_id: bank_id,
bank_1c_id: bank_1c_id
}
},
...config
})
}
@ -159,13 +174,14 @@ export default class DocumentService {
search: search || null,
limit: limit || 10,
offset: offset || 0
}
},
...config
})
}
// Get Bank
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
@ -174,13 +190,14 @@ export default class DocumentService {
params: {
bank_id: bank_id,
bank_1c_id: bank_1c_id
}
},
...config
})
}
// Add Org
static async addOrganization(data: IOrganization) {
return await axiosInstance.post(`/info/organization/org/`, data)
return await axiosInstance.post(`/info/organization/org/`, data, config)
}
// Update Org
@ -189,7 +206,8 @@ export default class DocumentService {
params: {
org_id: org_id,
org_1c_id: org_1c_id
}
},
...config
})
}
@ -199,7 +217,8 @@ export default class DocumentService {
params: {
org_id: org_id,
org_1c_id: org_1c_id
}
},
...config
})
}
@ -211,17 +230,18 @@ export default class DocumentService {
search: search || null,
limit: limit || 10,
offset: offset || 0
}
},
...config
})
}
// Get Org
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
static async addOrganizationBank(data: IOrganizationBank) {
return await axiosInstance.post(`/info/organization/org_bank`, data)
return await axiosInstance.post(`/info/organization/org_bank`, data, config)
}
}
Loading…
Cancel
Save