shared-ritm 1.1.79 → 1.1.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/shared-ritm.es.js +15 -12
  3. package/dist/shared-ritm.umd.js +3 -3
  4. package/dist/types/api/services/TasksService.d.ts +3 -0
  5. package/package.json +1 -1
  6. package/src/api/services/AuthService.ts +41 -41
  7. package/src/api/services/FileService.ts +15 -15
  8. package/src/api/services/TasksService.ts +132 -128
  9. package/src/api/settings/ApiService.ts +125 -125
  10. package/src/api/types/Api_Repairs.ts +93 -93
  11. package/src/common/app-button/AppButton.vue +173 -173
  12. package/src/common/app-date-picker/AppDatePicker.vue +79 -79
  13. package/src/common/app-icon/AppIcon.vue +104 -104
  14. package/src/common/app-input/AppInput.vue +147 -147
  15. package/src/common/app-layout/AppLayout.vue +63 -63
  16. package/src/common/app-layout/components/AppLayoutHeader.vue +123 -123
  17. package/src/common/app-loader/index.vue +43 -43
  18. package/src/common/app-page-layout/AppPageLayout.vue +122 -122
  19. package/src/common/app-sheet/AppSheet.vue +114 -114
  20. package/src/common/app-sidebar/AppSidebar.vue +168 -168
  21. package/src/common/app-sidebar/components/SidebarMenu.vue +37 -37
  22. package/src/common/app-sidebar/components/SidebarMenuItem.vue +139 -139
  23. package/src/common/app-toggle/AppToggle.vue +23 -23
  24. package/src/global.d.ts +1 -1
  25. package/src/icons/components/arrow-down-icon.vue +25 -25
  26. package/src/icons/components/arrow-frame-icon.vue +19 -19
  27. package/src/icons/components/arrow-square.vue +22 -22
  28. package/src/icons/header/flashIcon.vue +24 -24
  29. package/src/icons/header/notificationIcon.vue +18 -18
  30. package/src/icons/header/searchStatusIcon.vue +24 -24
  31. package/src/icons/header/smallCapsIcon.vue +34 -34
  32. package/src/icons/sidebar/assign-module-icon.vue +36 -36
  33. package/src/icons/sidebar/instrument-history-icon.vue +32 -32
  34. package/src/icons/sidebar/instrument-order-icon.vue +38 -38
  35. package/src/icons/sidebar/instrument-work-zone-icon.vue +18 -18
  36. package/src/icons/sidebar/instruments-icon.vue +45 -45
  37. package/src/icons/sidebar/logo-icon.vue +15 -15
  38. package/src/icons/sidebar/logout-icon.vue +13 -13
  39. package/src/icons/sidebar/modules-icon.vue +16 -16
  40. package/src/icons/sidebar/notifications-icon.vue +24 -24
  41. package/src/icons/sidebar/order-icon.vue +44 -44
  42. package/src/icons/sidebar/pass-icon.vue +38 -38
  43. package/src/icons/sidebar/positions-icon.vue +42 -42
  44. package/src/icons/sidebar/preorder-icon.vue +19 -19
  45. package/src/icons/sidebar/projects-icon.vue +31 -31
  46. package/src/icons/sidebar/repair-object-icon.vue +18 -18
  47. package/src/icons/sidebar/repairs-icon.vue +20 -20
  48. package/src/icons/sidebar/roles-icon.vue +26 -26
  49. package/src/icons/sidebar/status-history-icon.vue +24 -24
  50. package/src/icons/sidebar/tasks-icon.vue +28 -28
  51. package/src/icons/sidebar/tasks_tasks-icon.vue +39 -39
  52. package/src/icons/sidebar/tasks_today-icon.vue +27 -27
  53. package/src/icons/sidebar/teams-icon.vue +32 -32
  54. package/src/icons/sidebar/user-icon.vue +18 -18
  55. package/src/icons/sidebar/users-icon.vue +46 -46
  56. package/src/icons/sidebar/videosources-icon.vue +19 -19
  57. package/src/icons/sidebar/videowall-icon.vue +13 -13
  58. package/src/icons/sidebar/videozones-icon.vue +21 -21
  59. package/src/icons/sidebar/warehouses-icon.vue +43 -43
  60. package/src/icons/sidebar/workshop-icon.vue +100 -100
  61. package/src/icons/sidebar/workzones-icon.vue +22 -22
  62. package/src/main.ts +18 -18
  63. package/src/quasar-user-options.ts +17 -17
  64. package/src/router/index.ts +10 -10
  65. package/src/shims-vue.d.ts +5 -5
@@ -44,6 +44,9 @@ declare class TasksService extends ApiService {
44
44
  taskId: string;
45
45
  data: unknown;
46
46
  }): Promise<unknown>;
47
+ checkBranchBeforeCloseTask(payload: {
48
+ taskId: string;
49
+ }): Promise<unknown>;
47
50
  }
48
51
  export default function useTasksService(): TasksService;
49
52
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-ritm",
3
- "version": "1.1.79",
3
+ "version": "1.1.80",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -1,41 +1,41 @@
1
- import ApiService from '@/api/settings/ApiService'
2
-
3
- type LoginPayload = {
4
- email: string
5
- password: string
6
- }
7
-
8
- type LoginResponse = {
9
- token: string
10
- user: any
11
- }
12
-
13
- type ConfigResponse = any
14
-
15
- class AuthService extends ApiService {
16
- public login(email: string, password: string) {
17
- return this.post<LoginPayload, LoginResponse>(`/login`, {
18
- email,
19
- password,
20
- })
21
- }
22
-
23
- public logout() {
24
- return this.post<null, LoginResponse>(`/logout`, null)
25
- }
26
-
27
- public userInfo() {
28
- return this.get<any>(`/users/auth`)
29
- }
30
-
31
- public configs() {
32
- return this.get<ConfigResponse>(`/configs`)
33
- }
34
- }
35
-
36
- let api: AuthService
37
-
38
- export default function useAuthService() {
39
- if (!api) api = new AuthService()
40
- return api
41
- }
1
+ import ApiService from '@/api/settings/ApiService'
2
+
3
+ type LoginPayload = {
4
+ email: string
5
+ password: string
6
+ }
7
+
8
+ type LoginResponse = {
9
+ token: string
10
+ user: any
11
+ }
12
+
13
+ type ConfigResponse = any
14
+
15
+ class AuthService extends ApiService {
16
+ public login(email: string, password: string) {
17
+ return this.post<LoginPayload, LoginResponse>(`/login`, {
18
+ email,
19
+ password,
20
+ })
21
+ }
22
+
23
+ public logout() {
24
+ return this.post<null, LoginResponse>(`/logout`, null)
25
+ }
26
+
27
+ public userInfo() {
28
+ return this.get<any>(`/users/auth`)
29
+ }
30
+
31
+ public configs() {
32
+ return this.get<ConfigResponse>(`/configs`)
33
+ }
34
+ }
35
+
36
+ let api: AuthService
37
+
38
+ export default function useAuthService() {
39
+ if (!api) api = new AuthService()
40
+ return api
41
+ }
@@ -1,15 +1,15 @@
1
- import ApiService, { ResponseApi } from '@/api/settings/ApiService'
2
- import { Api_Files_Responsible_Dto } from '@/api/types/Api_Files'
3
-
4
- class FileService extends ApiService {
5
- public uploadFile(data: FormData): Promise<ResponseApi<Api_Files_Responsible_Dto>> {
6
- return this.post<FormData, any>(`/upload-file`, data, { headers: { 'Content-Type': 'multipart/form-data' } })
7
- }
8
- }
9
-
10
- let api: FileService
11
-
12
- export default function useFileService() {
13
- if (!api) api = new FileService()
14
- return api
15
- }
1
+ import ApiService, { ResponseApi } from '@/api/settings/ApiService'
2
+ import { Api_Files_Responsible_Dto } from '@/api/types/Api_Files'
3
+
4
+ class FileService extends ApiService {
5
+ public uploadFile(data: FormData): Promise<ResponseApi<Api_Files_Responsible_Dto>> {
6
+ return this.post<FormData, any>(`/upload-file`, data, { headers: { 'Content-Type': 'multipart/form-data' } })
7
+ }
8
+ }
9
+
10
+ let api: FileService
11
+
12
+ export default function useFileService() {
13
+ if (!api) api = new FileService()
14
+ return api
15
+ }
@@ -1,128 +1,132 @@
1
- import ApiService, { ResponseApi } from '@/api/settings/ApiService'
2
- import {
3
- Api_Task_Close_Reason,
4
- Api_Task_Instrument_Dto,
5
- Api_Task_Instrument_From_Warehouse,
6
- Api_Task_Module_Instrument_Condition,
7
- Api_Tasks_Dto,
8
- Api_Tasks_Task_Dto,
9
- } from '@/api/types/Api_Tasks'
10
- import { Api_Equipment_Full_Dto, Api_Task_Video_Source, Api_Task_Video_Source_Stream } from '@/api/types/Api_Repairs'
11
-
12
- class TasksService extends ApiService {
13
- public async fetchTaskById(id: string): Promise<ResponseApi<Api_Tasks_Task_Dto>> {
14
- return await this.get(`/tasks/${id}`)
15
- }
16
-
17
- public async fetchTasksList(params: any): Promise<ResponseApi<Api_Tasks_Dto[]>> {
18
- return await this.get('/list/tasks/search', { params })
19
- }
20
-
21
- public async fetchSubtasksList(id: string): Promise<ResponseApi<Api_Tasks_Dto[]>> {
22
- return await this.get(`/task/${id}/subtasks/list`)
23
- }
24
-
25
- public async fetchTaskBranch(id: string): Promise<ResponseApi<any>> {
26
- return await this.get(`/get_list_task_branch?task_id=${id}`)
27
- }
28
-
29
- public async fetchInstrumentsList(params: any): Promise<ResponseApi<any[]>> {
30
- return await this.get('admin/instruments', { params })
31
- }
32
-
33
- public async fetchInstrumentTypeListWithPreparedWarehouse(params: {
34
- page: number
35
- per_page: number
36
- 'filterList[taskId]'?: string | undefined
37
- search?: string
38
- }): Promise<Api_Task_Instrument_From_Warehouse[]> {
39
- return await this.get('/instrument_type/get_instrument_type_list_with_prepared_warehouse', { params })
40
- }
41
-
42
- public async fetchInstrumentsEquivalentList(params: any): Promise<ResponseApi<Api_Task_Instrument_Dto[]>> {
43
- return await this.get('tasks/instrument/list', { params })
44
- }
45
-
46
- public async fetchDiffInstruments(params: any): Promise<ResponseApi<Api_Task_Module_Instrument_Condition>> {
47
- return await this.get(`tasks/${params.taskId}/fill/module`, { params })
48
- }
49
-
50
- public async replaceInstruments(payload: any): Promise<ResponseApi<any>> {
51
- return await this.post(`/instruments/equivalent/attach`, payload)
52
- }
53
- public async fetchTaskUsagePersonal(params: any): Promise<ResponseApi<unknown[]>> {
54
- return await this.get(`tasks/${params.taskId}/usage/users`, { params })
55
- }
56
-
57
- public fetchEquipment(params: any): Promise<ResponseApi<Api_Equipment_Full_Dto[]>> {
58
- return this.get('repairs/equipment/list', { params })
59
- }
60
-
61
- public fetchTaskVideoSources(params: any): Promise<ResponseApi<Api_Task_Video_Source[]>> {
62
- return this.get('work_zone/get_list_video_source', { params })
63
- }
64
-
65
- public fetchTaskVideoSourcesStream(params: any): Promise<ResponseApi<Api_Task_Video_Source_Stream[]>> {
66
- return this.get('horizon/video-source', { params })
67
- }
68
-
69
- public createWorkZone(payload: any): Promise<unknown> {
70
- return this.post('admin/work-zones', payload)
71
- }
72
-
73
- public async createTask(payload: any): Promise<ResponseApi<any>> {
74
- return await this.post(`tasks`, payload)
75
- }
76
-
77
- public async editTask(payload: any): Promise<ResponseApi<any>> {
78
- return await this.put(`tasks/${payload.taskId}`, payload.data)
79
- }
80
-
81
- public async mergeTask(payload: { name: string; tasks_id: string[] }): Promise<ResponseApi<any>> {
82
- return await this.post(`tasks/merge`, payload)
83
- }
84
-
85
- public async deleteTask(id: string): Promise<any> {
86
- return await this.delete(`tasks/${id}`)
87
- }
88
-
89
- public async changeStatus(payload: { taskId: string; data: unknown }): Promise<unknown> {
90
- const { taskId, data } = payload
91
- return await this.put(`task/${taskId}/change-status`, data)
92
- }
93
-
94
- public async uploadComment(payload: unknown): Promise<unknown> {
95
- return await this.post('comments', payload)
96
- }
97
-
98
- public async deleteComment(commentId: string): Promise<unknown> {
99
- return await this.delete(`comments/${commentId}`)
100
- }
101
-
102
- public async editComment(payload: { commentId: string; data: unknown }): Promise<unknown> {
103
- const { commentId, data } = payload
104
- return await this.put(`comments/${commentId}`, data)
105
- }
106
-
107
- public async saveMetrics(payload: unknown): Promise<unknown> {
108
- return await this.put('/update_quality_metrics', payload)
109
- }
110
-
111
- public async checkReasonForStatus(payload): Promise<Api_Task_Close_Reason> {
112
- return await this.post('/tasks/check_reason_for_task', payload)
113
- }
114
-
115
- public async verifyTaskStatus(payload: { taskId: string; data: unknown }): Promise<unknown> {
116
- const { taskId, data } = payload
117
- return await this.get(`/task/${taskId}/change-status/verification`, {
118
- params: data,
119
- })
120
- }
121
- }
122
-
123
- let api: TasksService
124
-
125
- export default function useTasksService() {
126
- if (!api) api = new TasksService()
127
- return api
128
- }
1
+ import ApiService, { ResponseApi } from '@/api/settings/ApiService'
2
+ import {
3
+ Api_Task_Close_Reason,
4
+ Api_Task_Instrument_Dto,
5
+ Api_Task_Instrument_From_Warehouse,
6
+ Api_Task_Module_Instrument_Condition,
7
+ Api_Tasks_Dto,
8
+ Api_Tasks_Task_Dto,
9
+ } from '@/api/types/Api_Tasks'
10
+ import { Api_Equipment_Full_Dto, Api_Task_Video_Source, Api_Task_Video_Source_Stream } from '@/api/types/Api_Repairs'
11
+
12
+ class TasksService extends ApiService {
13
+ public async fetchTaskById(id: string): Promise<ResponseApi<Api_Tasks_Task_Dto>> {
14
+ return await this.get(`/tasks/${id}`)
15
+ }
16
+
17
+ public async fetchTasksList(params: any): Promise<ResponseApi<Api_Tasks_Dto[]>> {
18
+ return await this.get('/list/tasks/search', { params })
19
+ }
20
+
21
+ public async fetchSubtasksList(id: string): Promise<ResponseApi<Api_Tasks_Dto[]>> {
22
+ return await this.get(`/task/${id}/subtasks/list`)
23
+ }
24
+
25
+ public async fetchTaskBranch(id: string): Promise<ResponseApi<any>> {
26
+ return await this.get(`/get_list_task_branch?task_id=${id}`)
27
+ }
28
+
29
+ public async fetchInstrumentsList(params: any): Promise<ResponseApi<any[]>> {
30
+ return await this.get('admin/instruments', { params })
31
+ }
32
+
33
+ public async fetchInstrumentTypeListWithPreparedWarehouse(params: {
34
+ page: number
35
+ per_page: number
36
+ 'filterList[taskId]'?: string | undefined
37
+ search?: string
38
+ }): Promise<Api_Task_Instrument_From_Warehouse[]> {
39
+ return await this.get('/instrument_type/get_instrument_type_list_with_prepared_warehouse', { params })
40
+ }
41
+
42
+ public async fetchInstrumentsEquivalentList(params: any): Promise<ResponseApi<Api_Task_Instrument_Dto[]>> {
43
+ return await this.get('tasks/instrument/list', { params })
44
+ }
45
+
46
+ public async fetchDiffInstruments(params: any): Promise<ResponseApi<Api_Task_Module_Instrument_Condition>> {
47
+ return await this.get(`tasks/${params.taskId}/fill/module`, { params })
48
+ }
49
+
50
+ public async replaceInstruments(payload: any): Promise<ResponseApi<any>> {
51
+ return await this.post(`/instruments/equivalent/attach`, payload)
52
+ }
53
+ public async fetchTaskUsagePersonal(params: any): Promise<ResponseApi<unknown[]>> {
54
+ return await this.get(`tasks/${params.taskId}/usage/users`, { params })
55
+ }
56
+
57
+ public fetchEquipment(params: any): Promise<ResponseApi<Api_Equipment_Full_Dto[]>> {
58
+ return this.get('repairs/equipment/list', { params })
59
+ }
60
+
61
+ public fetchTaskVideoSources(params: any): Promise<ResponseApi<Api_Task_Video_Source[]>> {
62
+ return this.get('work_zone/get_list_video_source', { params })
63
+ }
64
+
65
+ public fetchTaskVideoSourcesStream(params: any): Promise<ResponseApi<Api_Task_Video_Source_Stream[]>> {
66
+ return this.get('horizon/video-source', { params })
67
+ }
68
+
69
+ public createWorkZone(payload: any): Promise<unknown> {
70
+ return this.post('admin/work-zones', payload)
71
+ }
72
+
73
+ public async createTask(payload: any): Promise<ResponseApi<any>> {
74
+ return await this.post(`tasks`, payload)
75
+ }
76
+
77
+ public async editTask(payload: any): Promise<ResponseApi<any>> {
78
+ return await this.put(`tasks/${payload.taskId}`, payload.data)
79
+ }
80
+
81
+ public async mergeTask(payload: { name: string; tasks_id: string[] }): Promise<ResponseApi<any>> {
82
+ return await this.post(`tasks/merge`, payload)
83
+ }
84
+
85
+ public async deleteTask(id: string): Promise<any> {
86
+ return await this.delete(`tasks/${id}`)
87
+ }
88
+
89
+ public async changeStatus(payload: { taskId: string; data: unknown }): Promise<unknown> {
90
+ const { taskId, data } = payload
91
+ return await this.put(`task/${taskId}/change-status`, data)
92
+ }
93
+
94
+ public async uploadComment(payload: unknown): Promise<unknown> {
95
+ return await this.post('comments', payload)
96
+ }
97
+
98
+ public async deleteComment(commentId: string): Promise<unknown> {
99
+ return await this.delete(`comments/${commentId}`)
100
+ }
101
+
102
+ public async editComment(payload: { commentId: string; data: unknown }): Promise<unknown> {
103
+ const { commentId, data } = payload
104
+ return await this.put(`comments/${commentId}`, data)
105
+ }
106
+
107
+ public async saveMetrics(payload: unknown): Promise<unknown> {
108
+ return await this.put('/update_quality_metrics', payload)
109
+ }
110
+
111
+ public async checkReasonForStatus(payload): Promise<Api_Task_Close_Reason> {
112
+ return await this.post('/tasks/check_reason_for_task', payload)
113
+ }
114
+
115
+ public async verifyTaskStatus(payload: { taskId: string; data: unknown }): Promise<unknown> {
116
+ const { taskId, data } = payload
117
+ return await this.get(`/task/${taskId}/change-status/verification`, {
118
+ params: data,
119
+ })
120
+ }
121
+
122
+ public async checkBranchBeforeCloseTask(payload: { taskId: string }): Promise<unknown> {
123
+ return await this.post(`/check_branch_before_close_task`, payload)
124
+ }
125
+ }
126
+
127
+ let api: TasksService
128
+
129
+ export default function useTasksService() {
130
+ if (!api) api = new TasksService()
131
+ return api
132
+ }
@@ -1,125 +1,125 @@
1
- import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
-
3
- export enum ApiServiceType {
4
- SERVICE_AUTH = 'SERVICE_AUTH',
5
- }
6
-
7
- export type ResponseApi<T> = {
8
- count: number
9
- current_page: number
10
- data: T
11
- per_page: number
12
- total: number
13
- total_pages: number
14
- }
15
-
16
- export default class ApiService {
17
- private axiosInstance: AxiosInstance
18
-
19
- constructor() {
20
- this.axiosInstance = axios.create({
21
- baseURL: process.env.VUE_APP_BACKEND,
22
- headers: {
23
- 'Content-Type': 'application/json',
24
- },
25
- })
26
-
27
- this.axiosInstance.interceptors.request.use(
28
- (config: InternalAxiosRequestConfig) => {
29
- const token = this.getToken()
30
- if (token && config.headers) {
31
- config.headers.Authorization = `Bearer ${token}`
32
- }
33
- return config
34
- },
35
- (error: AxiosError) => {
36
- return Promise.reject(error)
37
- },
38
- )
39
-
40
- this.axiosInstance.interceptors.response.use(
41
- (response: AxiosResponse) => {
42
- return response.data
43
- },
44
- (error: AxiosError) => {
45
- if (error.response?.status === 401 || error.response?.status === 403) {
46
- this.logout()
47
- }
48
- return Promise.reject(error)
49
- },
50
- )
51
- }
52
-
53
- private getToken() {
54
- return localStorage.getItem('token')
55
- }
56
-
57
- private removeToken() {
58
- localStorage.removeItem('token')
59
- }
60
-
61
- public logout(): void {
62
- this.removeToken()
63
- window.location.href = '/sign-in'
64
- }
65
-
66
- private handleError(error: AxiosError): void {
67
- if (error.response) {
68
- console.error('API Error:', error.response.status, error.response.data)
69
- } else if (error.request) {
70
- console.error('No response received:', error.request)
71
- } else {
72
- console.error('Error during request setup:', error.message)
73
- }
74
- }
75
-
76
- protected async get<T>(url: string, options?: AxiosRequestConfig) {
77
- try {
78
- const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
79
- return response?.data ?? (response as unknown as T)
80
- } catch (error) {
81
- const axiosError = error as AxiosError
82
- this.handleError(axiosError)
83
- throw error
84
- }
85
- }
86
-
87
- protected async delete<T>(url: string, options?: AxiosRequestConfig) {
88
- try {
89
- return await this.axiosInstance.delete<T>(url, options)
90
- } catch (error) {
91
- const axiosError = error as AxiosError
92
- this.handleError(axiosError)
93
- throw error
94
- }
95
- }
96
-
97
- protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
98
- try {
99
- const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
100
- return response.data
101
- } catch (error) {
102
- const axiosError = error as AxiosError
103
- this.handleError(axiosError)
104
- throw error
105
- }
106
- }
107
-
108
- // protected patch<T1, T2>(url: string, payload: T1, type: ApiServiceType, options?: AxiosRequestConfig): Promise<T2> {
109
- // return axios
110
- // .patch<T1, AxiosResponse<T2>>(apiServiceUrls[type] + url, payload, options)
111
- // .catch((err: AxiosError) => processError401<T2>(err))
112
- // .then(extractData)
113
- // }
114
- //
115
- protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
116
- try {
117
- const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
118
- return response.data
119
- } catch (error) {
120
- const axiosError = error as AxiosError
121
- this.handleError(axiosError)
122
- throw error
123
- }
124
- }
125
- }
1
+ import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
+
3
+ export enum ApiServiceType {
4
+ SERVICE_AUTH = 'SERVICE_AUTH',
5
+ }
6
+
7
+ export type ResponseApi<T> = {
8
+ count: number
9
+ current_page: number
10
+ data: T
11
+ per_page: number
12
+ total: number
13
+ total_pages: number
14
+ }
15
+
16
+ export default class ApiService {
17
+ private axiosInstance: AxiosInstance
18
+
19
+ constructor() {
20
+ this.axiosInstance = axios.create({
21
+ baseURL: process.env.VUE_APP_BACKEND,
22
+ headers: {
23
+ 'Content-Type': 'application/json',
24
+ },
25
+ })
26
+
27
+ this.axiosInstance.interceptors.request.use(
28
+ (config: InternalAxiosRequestConfig) => {
29
+ const token = this.getToken()
30
+ if (token && config.headers) {
31
+ config.headers.Authorization = `Bearer ${token}`
32
+ }
33
+ return config
34
+ },
35
+ (error: AxiosError) => {
36
+ return Promise.reject(error)
37
+ },
38
+ )
39
+
40
+ this.axiosInstance.interceptors.response.use(
41
+ (response: AxiosResponse) => {
42
+ return response.data
43
+ },
44
+ (error: AxiosError) => {
45
+ if (error.response?.status === 401 || error.response?.status === 403) {
46
+ this.logout()
47
+ }
48
+ return Promise.reject(error)
49
+ },
50
+ )
51
+ }
52
+
53
+ private getToken() {
54
+ return localStorage.getItem('token')
55
+ }
56
+
57
+ private removeToken() {
58
+ localStorage.removeItem('token')
59
+ }
60
+
61
+ public logout(): void {
62
+ this.removeToken()
63
+ window.location.href = '/sign-in'
64
+ }
65
+
66
+ private handleError(error: AxiosError): void {
67
+ if (error.response) {
68
+ console.error('API Error:', error.response.status, error.response.data)
69
+ } else if (error.request) {
70
+ console.error('No response received:', error.request)
71
+ } else {
72
+ console.error('Error during request setup:', error.message)
73
+ }
74
+ }
75
+
76
+ protected async get<T>(url: string, options?: AxiosRequestConfig) {
77
+ try {
78
+ const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
79
+ return response?.data ?? (response as unknown as T)
80
+ } catch (error) {
81
+ const axiosError = error as AxiosError
82
+ this.handleError(axiosError)
83
+ throw error
84
+ }
85
+ }
86
+
87
+ protected async delete<T>(url: string, options?: AxiosRequestConfig) {
88
+ try {
89
+ return await this.axiosInstance.delete<T>(url, options)
90
+ } catch (error) {
91
+ const axiosError = error as AxiosError
92
+ this.handleError(axiosError)
93
+ throw error
94
+ }
95
+ }
96
+
97
+ protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
98
+ try {
99
+ const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
100
+ return response.data
101
+ } catch (error) {
102
+ const axiosError = error as AxiosError
103
+ this.handleError(axiosError)
104
+ throw error
105
+ }
106
+ }
107
+
108
+ // protected patch<T1, T2>(url: string, payload: T1, type: ApiServiceType, options?: AxiosRequestConfig): Promise<T2> {
109
+ // return axios
110
+ // .patch<T1, AxiosResponse<T2>>(apiServiceUrls[type] + url, payload, options)
111
+ // .catch((err: AxiosError) => processError401<T2>(err))
112
+ // .then(extractData)
113
+ // }
114
+ //
115
+ protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
116
+ try {
117
+ const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
118
+ return response.data
119
+ } catch (error) {
120
+ const axiosError = error as AxiosError
121
+ this.handleError(axiosError)
122
+ throw error
123
+ }
124
+ }
125
+ }