shared-ritm 1.2.125 → 1.2.127

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 (128) hide show
  1. package/README.md +103 -103
  2. package/dist/index.css +1 -1
  3. package/dist/shared-ritm.es.js +283 -285
  4. package/dist/shared-ritm.umd.js +8 -8
  5. package/package.json +64 -64
  6. package/src/App.vue +2461 -2461
  7. package/src/api/services/AuthService.ts +53 -53
  8. package/src/api/services/BrigadesService.ts +32 -32
  9. package/src/api/services/CommentsService.ts +24 -24
  10. package/src/api/services/ControlsService.ts +73 -73
  11. package/src/api/services/EquipmentService.ts +29 -29
  12. package/src/api/services/FileService.ts +17 -17
  13. package/src/api/services/GanttService.ts +17 -17
  14. package/src/api/services/InstrumentsService.ts +63 -63
  15. package/src/api/services/MetricsService.ts +110 -110
  16. package/src/api/services/ModulesService.ts +27 -27
  17. package/src/api/services/ProjectsService.ts +79 -79
  18. package/src/api/services/RepairsService.ts +123 -123
  19. package/src/api/services/SearchService.ts +22 -22
  20. package/src/api/services/TasksService.ts +145 -145
  21. package/src/api/services/UserService.ts +101 -101
  22. package/src/api/services/VideoService.ts +71 -71
  23. package/src/api/settings/ApiService.ts +124 -124
  24. package/src/api/types/Api_Auth.ts +86 -86
  25. package/src/api/types/Api_Brigades.ts +36 -36
  26. package/src/api/types/Api_Comment.ts +40 -40
  27. package/src/api/types/Api_Controls.ts +93 -93
  28. package/src/api/types/Api_Equipment.ts +3 -3
  29. package/src/api/types/Api_Files.ts +7 -7
  30. package/src/api/types/Api_Instruments.ts +136 -136
  31. package/src/api/types/Api_Modules.ts +21 -21
  32. package/src/api/types/Api_Projects.ts +60 -60
  33. package/src/api/types/Api_Repairs.ts +117 -117
  34. package/src/api/types/Api_Search.ts +77 -77
  35. package/src/api/types/Api_Service.ts +9 -9
  36. package/src/api/types/Api_Tasks.ts +319 -319
  37. package/src/api/types/Api_User.ts +117 -117
  38. package/src/api/types/Api_Video.ts +140 -140
  39. package/src/common/app-button/AppButton.vue +173 -173
  40. package/src/common/app-checkbox/AppCheckbox.vue +26 -26
  41. package/src/common/app-date-picker/AppDatePicker.vue +81 -81
  42. package/src/common/app-datepicker/AppDatepicker.vue +165 -165
  43. package/src/common/app-dialogs/AppConfirmDialog.vue +99 -99
  44. package/src/common/app-dropdown/AppDropdown.vue +37 -37
  45. package/src/common/app-icon/AppIcon.vue +108 -108
  46. package/src/common/app-input/AppInput.vue +148 -148
  47. package/src/common/app-input-new/AppInputNew.vue +175 -175
  48. package/src/common/app-input-search/AppInputSearch.vue +174 -174
  49. package/src/common/app-layout/AppLayout.vue +84 -84
  50. package/src/common/app-layout/components/AppLayoutHeader.vue +273 -273
  51. package/src/common/app-layout/components/AppLayoutPage.vue +16 -16
  52. package/src/common/app-loader/index.vue +43 -43
  53. package/src/common/app-page-layout/AppPageLayout.vue +122 -122
  54. package/src/common/app-select/AppSelect.vue +157 -157
  55. package/src/common/app-sheet/AppSheet.vue +120 -120
  56. package/src/common/app-sheet-new/AppSheetNew.vue +246 -246
  57. package/src/common/app-sidebar/AppSidebar.vue +168 -168
  58. package/src/common/app-sidebar/components/SidebarMenu.vue +37 -37
  59. package/src/common/app-sidebar/components/SidebarMenuItem.vue +148 -148
  60. package/src/common/app-table/AppTable.vue +308 -308
  61. package/src/common/app-table/AppTableLayout.vue +137 -137
  62. package/src/common/app-table/components/ModalSelect.vue +281 -281
  63. package/src/common/app-table/components/TableModal.vue +356 -356
  64. package/src/common/app-table/components/TablePagination.vue +152 -152
  65. package/src/common/app-table/controllers/useBaseTable.ts +45 -45
  66. package/src/common/app-table/controllers/useColumnSelector.ts +38 -38
  67. package/src/common/app-table/controllers/useTableModel.ts +102 -102
  68. package/src/common/app-toggle/AppToggle.vue +24 -24
  69. package/src/common/app-wrapper/AppWrapper.vue +28 -28
  70. package/src/global.d.ts +1 -1
  71. package/src/icons/components/arrow-down-icon.vue +25 -25
  72. package/src/icons/components/arrow-frame-icon.vue +19 -19
  73. package/src/icons/components/arrow-square.vue +22 -22
  74. package/src/icons/components/table-filter-icon.vue +30 -30
  75. package/src/icons/dialogs/RemoveIcon.vue +12 -12
  76. package/src/icons/dialogs/SafetyIcon.vue +12 -12
  77. package/src/icons/header/NotificationIcon.vue +18 -18
  78. package/src/icons/header/PersonIcon.vue +11 -11
  79. package/src/icons/header/SettingIcon.vue +14 -14
  80. package/src/icons/header/flashIcon.vue +24 -24
  81. package/src/icons/header/searchStatusIcon.vue +24 -24
  82. package/src/icons/header/smallCapsIcon.vue +34 -34
  83. package/src/icons/sidebar/assign-module-icon.vue +36 -36
  84. package/src/icons/sidebar/instrument-history-icon.vue +32 -32
  85. package/src/icons/sidebar/instrument-order-icon.vue +38 -38
  86. package/src/icons/sidebar/instrument-work-zone-icon.vue +18 -18
  87. package/src/icons/sidebar/instruments-icon.vue +45 -45
  88. package/src/icons/sidebar/logo-icon.vue +15 -15
  89. package/src/icons/sidebar/logout-icon.vue +13 -13
  90. package/src/icons/sidebar/modules-icon.vue +16 -16
  91. package/src/icons/sidebar/notifications-icon.vue +24 -24
  92. package/src/icons/sidebar/order-icon.vue +44 -44
  93. package/src/icons/sidebar/pass-icon.vue +38 -38
  94. package/src/icons/sidebar/positions-icon.vue +42 -42
  95. package/src/icons/sidebar/preorder-icon.vue +19 -19
  96. package/src/icons/sidebar/projects-icon.vue +31 -31
  97. package/src/icons/sidebar/repair-object-icon.vue +18 -18
  98. package/src/icons/sidebar/repairs-icon.vue +20 -20
  99. package/src/icons/sidebar/roles-icon.vue +26 -26
  100. package/src/icons/sidebar/status-history-icon.vue +24 -24
  101. package/src/icons/sidebar/tasks-icon.vue +28 -28
  102. package/src/icons/sidebar/tasks_tasks-icon.vue +39 -39
  103. package/src/icons/sidebar/tasks_today-icon.vue +27 -27
  104. package/src/icons/sidebar/teams-icon.vue +32 -32
  105. package/src/icons/sidebar/user-icon.vue +18 -18
  106. package/src/icons/sidebar/users-icon.vue +46 -46
  107. package/src/icons/sidebar/videosources-icon.vue +19 -19
  108. package/src/icons/sidebar/videowall-icon.vue +13 -13
  109. package/src/icons/sidebar/videozones-icon.vue +21 -21
  110. package/src/icons/sidebar/warehouses-icon.vue +43 -43
  111. package/src/icons/sidebar/workshop-icon.vue +100 -100
  112. package/src/icons/sidebar/workzones-icon.vue +22 -22
  113. package/src/icons/task/attention-icon.vue +13 -13
  114. package/src/icons/task/clock-icon.vue +10 -10
  115. package/src/icons/task/delete-icon.vue +10 -10
  116. package/src/icons/task/fire-icon.vue +16 -16
  117. package/src/index.ts +123 -123
  118. package/src/main.ts +28 -28
  119. package/src/quasar-user-options.ts +17 -17
  120. package/src/router/index.ts +10 -10
  121. package/src/shared/styles/general.css +124 -124
  122. package/src/shims-vue.d.ts +5 -5
  123. package/src/styles/variables.sass +12 -12
  124. package/src/utils/confirm.ts +12 -12
  125. package/src/utils/faceApiHelper.ts +132 -132
  126. package/src/utils/helpers.ts +59 -59
  127. package/src/utils/notification.ts +9 -9
  128. package/dist/types/api/services/PhotoService.d.ts +0 -40
@@ -1,101 +1,101 @@
1
- import ApiService from '../settings/ApiService'
2
- import {
3
- Api_User,
4
- Api_User_Create,
5
- Api_User_Delete_Body,
6
- Api_User_Delete_Photos_Body,
7
- Api_User_Position,
8
- Api_User_Role,
9
- Api_User_Team,
10
- Api_User_Team_Search,
11
- } from '../types/Api_User'
12
- import { ResponseApi } from '../types/Api_Service'
13
-
14
- class UserService extends ApiService {
15
- public async editUser({ id, model }: { id: string; model: any }): Promise<Api_User> {
16
- return await this.put<Partial<Api_User>, Api_User>(`/admin/users/${id}`, model)
17
- }
18
-
19
- public async getUser(id: string): Promise<Api_User> {
20
- return await this.get<Api_User>(`/admin/users/${id}`)
21
- }
22
-
23
- public async createUser(model: Api_User_Create): Promise<Api_User> {
24
- return await this.post<Api_User_Create, Api_User>('/admin/users', model)
25
- }
26
-
27
- public async deleteUser({
28
- user_id,
29
- archive_reason,
30
- }: Api_User_Delete_Body): Promise<{ data: boolean; status: number }> {
31
- return await this.post(`/users/archive_user`, { user_id, archive_reason })
32
- }
33
-
34
- public async deleteUserPhotos({
35
- user_id,
36
- photos,
37
- }: Api_User_Delete_Photos_Body): Promise<{ data: boolean; status: number }> {
38
- return await this.post(`/users/photos/delete`, { user_id, photos })
39
- }
40
-
41
- public async restoreUser(user_id: string): Promise<{ data: boolean; status: number }> {
42
- return await this.post(`/users/restore_user`, { user_id })
43
- }
44
-
45
- public async getRoles(params?: { per_page?: number }): Promise<ResponseApi<Api_User_Role[]>> {
46
- return await this.get<ResponseApi<Api_User_Role[]>>('/search/roles', { params })
47
- }
48
-
49
- public async getPositions(params?: { per_page?: number }): Promise<ResponseApi<Api_User_Position[]>> {
50
- return await this.get<ResponseApi<Api_User_Position[]>>('/search/positions', { params })
51
- }
52
-
53
- public async createPosition(body: Partial<Api_User_Position>): Promise<ResponseApi<Api_User_Position>> {
54
- return await this.post<Partial<Api_User_Position>, ResponseApi<Api_User_Position>>('/admin/positions', body)
55
- }
56
-
57
- public async editPosition(id: string, body: Partial<Api_User_Position>): Promise<ResponseApi<Api_User_Position>> {
58
- return await this.put<Partial<Api_User_Position>, ResponseApi<Api_User_Position>>(`/admin/positions/${id}`, body)
59
- }
60
-
61
- public async deletePosition(id: string): Promise<{ data: boolean; status: number }> {
62
- return await this.delete(`/admin/positions/${id}`)
63
- }
64
-
65
- public async getTeams(params?: { per_page?: number }): Promise<ResponseApi<Api_User_Team_Search[]>> {
66
- return await this.get<ResponseApi<Api_User_Team_Search[]>>('/search/teams', { params })
67
- }
68
-
69
- public async createTeam(body: Partial<Api_User_Team_Search>): Promise<ResponseApi<Api_User_Team>> {
70
- return await this.post<Partial<Api_User_Team_Search>, ResponseApi<Api_User_Team>>('/teams', body)
71
- }
72
-
73
- public async editTeam(id: string, body: Partial<Api_User_Team_Search>): Promise<{ data: boolean; status: number }> {
74
- return await this.patch<Partial<Api_User_Team_Search>, { data: boolean; status: number }>(`/teams/${id}`, body)
75
- }
76
-
77
- public async deleteTeam(id: string): Promise<{ data: boolean; status: number }> {
78
- return await this.delete(`/teams/${id}`)
79
- }
80
-
81
- public async checkUserVectors(id: string): Promise<{ count: number }> {
82
- return await this.get(`/user/get-vectors/${id}`)
83
- }
84
-
85
- public async addUserVectors(formData: FormData): Promise<{ response: string }> {
86
- return await this.post(`/user/add-vector`, formData, {
87
- headers: { 'Content-Type': 'multipart/form-data' },
88
- })
89
- }
90
-
91
- public async removeUserVectors(id: string): Promise<unknown> {
92
- return await this.delete(`/user/delete-vectors/${id}`)
93
- }
94
- }
95
-
96
- let api: UserService
97
-
98
- export default function useUserService() {
99
- if (!api) api = new UserService()
100
- return api
101
- }
1
+ import ApiService from '../settings/ApiService'
2
+ import {
3
+ Api_User,
4
+ Api_User_Create,
5
+ Api_User_Delete_Body,
6
+ Api_User_Delete_Photos_Body,
7
+ Api_User_Position,
8
+ Api_User_Role,
9
+ Api_User_Team,
10
+ Api_User_Team_Search,
11
+ } from '../types/Api_User'
12
+ import { ResponseApi } from '../types/Api_Service'
13
+
14
+ class UserService extends ApiService {
15
+ public async editUser({ id, model }: { id: string; model: any }): Promise<Api_User> {
16
+ return await this.put<Partial<Api_User>, Api_User>(`/admin/users/${id}`, model)
17
+ }
18
+
19
+ public async getUser(id: string): Promise<Api_User> {
20
+ return await this.get<Api_User>(`/admin/users/${id}`)
21
+ }
22
+
23
+ public async createUser(model: Api_User_Create): Promise<Api_User> {
24
+ return await this.post<Api_User_Create, Api_User>('/admin/users', model)
25
+ }
26
+
27
+ public async deleteUser({
28
+ user_id,
29
+ archive_reason,
30
+ }: Api_User_Delete_Body): Promise<{ data: boolean; status: number }> {
31
+ return await this.post(`/users/archive_user`, { user_id, archive_reason })
32
+ }
33
+
34
+ public async deleteUserPhotos({
35
+ user_id,
36
+ photos,
37
+ }: Api_User_Delete_Photos_Body): Promise<{ data: boolean; status: number }> {
38
+ return await this.post(`/users/photos/delete`, { user_id, photos })
39
+ }
40
+
41
+ public async restoreUser(user_id: string): Promise<{ data: boolean; status: number }> {
42
+ return await this.post(`/users/restore_user`, { user_id })
43
+ }
44
+
45
+ public async getRoles(params?: { per_page?: number }): Promise<ResponseApi<Api_User_Role[]>> {
46
+ return await this.get<ResponseApi<Api_User_Role[]>>('/search/roles', { params })
47
+ }
48
+
49
+ public async getPositions(params?: { per_page?: number }): Promise<ResponseApi<Api_User_Position[]>> {
50
+ return await this.get<ResponseApi<Api_User_Position[]>>('/search/positions', { params })
51
+ }
52
+
53
+ public async createPosition(body: Partial<Api_User_Position>): Promise<ResponseApi<Api_User_Position>> {
54
+ return await this.post<Partial<Api_User_Position>, ResponseApi<Api_User_Position>>('/admin/positions', body)
55
+ }
56
+
57
+ public async editPosition(id: string, body: Partial<Api_User_Position>): Promise<ResponseApi<Api_User_Position>> {
58
+ return await this.put<Partial<Api_User_Position>, ResponseApi<Api_User_Position>>(`/admin/positions/${id}`, body)
59
+ }
60
+
61
+ public async deletePosition(id: string): Promise<{ data: boolean; status: number }> {
62
+ return await this.delete(`/admin/positions/${id}`)
63
+ }
64
+
65
+ public async getTeams(params?: { per_page?: number }): Promise<ResponseApi<Api_User_Team_Search[]>> {
66
+ return await this.get<ResponseApi<Api_User_Team_Search[]>>('/search/teams', { params })
67
+ }
68
+
69
+ public async createTeam(body: Partial<Api_User_Team_Search>): Promise<ResponseApi<Api_User_Team>> {
70
+ return await this.post<Partial<Api_User_Team_Search>, ResponseApi<Api_User_Team>>('/teams', body)
71
+ }
72
+
73
+ public async editTeam(id: string, body: Partial<Api_User_Team_Search>): Promise<{ data: boolean; status: number }> {
74
+ return await this.patch<Partial<Api_User_Team_Search>, { data: boolean; status: number }>(`/teams/${id}`, body)
75
+ }
76
+
77
+ public async deleteTeam(id: string): Promise<{ data: boolean; status: number }> {
78
+ return await this.delete(`/teams/${id}`)
79
+ }
80
+
81
+ public async checkUserVectors(id: string): Promise<{ count: number }> {
82
+ return await this.get(`/user/get-vectors/${id}`)
83
+ }
84
+
85
+ public async addUserVectors(formData: FormData): Promise<{ response: string }> {
86
+ return await this.post(`/user/add-vector`, formData, {
87
+ headers: { 'Content-Type': 'multipart/form-data' },
88
+ })
89
+ }
90
+
91
+ public async removeUserVectors(id: string): Promise<unknown> {
92
+ return await this.delete(`/user/delete-vectors/${id}`)
93
+ }
94
+ }
95
+
96
+ let api: UserService
97
+
98
+ export default function useUserService() {
99
+ if (!api) api = new UserService()
100
+ return api
101
+ }
@@ -1,71 +1,71 @@
1
- import ApiService from '../settings/ApiService'
2
- import { ResponseApi } from '@/api/types/Api_Service'
3
- import {
4
- Api_Video_Source_By_Repair,
5
- Api_Video_Source_Create,
6
- Api_Video_Source_Search,
7
- Api_Work_Zone,
8
- Api_Work_Zone_Search,
9
- } from '@/api/types/Api_Video'
10
-
11
- class VideoService extends ApiService {
12
- public async startVideoAnalytics(): Promise<boolean> {
13
- return await this.post('/statanly/start', null)
14
- }
15
-
16
- public reloadVideoAnalytics(ids: string[]): Promise<any> {
17
- return this.post('/horizon/video-source/reload', { video_source_ids: ids })
18
- }
19
-
20
- public hardReloadStream(): Promise<any> {
21
- return this.post('horizon/video-source/streams/add', null)
22
- }
23
-
24
- public async fetchWorkZones(params?: any): Promise<ResponseApi<Api_Work_Zone_Search[]>> {
25
- return await this.get('/search/work_zones', { params })
26
- }
27
-
28
- public async fetchWorkZone(id: string): Promise<ResponseApi<Api_Work_Zone>> {
29
- return await this.get(`/work_zone/get_work_zone/${id}`)
30
- }
31
-
32
- public async editWorkZone(id: string, body: { title: string }): Promise<{ data: Api_Work_Zone; status: number }> {
33
- return await this.put(`/admin/work-zones/${id}`, body)
34
- }
35
-
36
- public async deleteWorkZone(id: string): Promise<{ data: boolean; status: number }> {
37
- return await this.delete(`/admin/work-zones/${id}`)
38
- }
39
-
40
- public async fetchVideoSources(params?: any): Promise<ResponseApi<Api_Video_Source_Search[]>> {
41
- return await this.get('/search/video_sources', { params })
42
- }
43
-
44
- public async createVideoSource(
45
- body: Api_Video_Source_Create,
46
- ): Promise<{ data: Api_Video_Source_Search; status: number }> {
47
- return await this.post('horizon/video-source', body)
48
- }
49
-
50
- public async editVideoSource(
51
- id: string,
52
- body: Partial<Api_Video_Source_Create>,
53
- ): Promise<{ data: Api_Video_Source_Search; status: number }> {
54
- return await this.put(`/horizon/video-source/${id}`, body)
55
- }
56
-
57
- public async deleteVideoSource(id: string): Promise<void> {
58
- await this.delete(`/horizon/video-source/${id}`)
59
- }
60
-
61
- public async fetchListRepairsVideoSource(params?: any): Promise<Api_Video_Source_By_Repair[]> {
62
- return await this.get('work_zone/get_list_video_source_by_repair', { params })
63
- }
64
- }
65
-
66
- let api: VideoService
67
-
68
- export default function useVideoService() {
69
- if (!api) api = new VideoService()
70
- return api
71
- }
1
+ import ApiService from '../settings/ApiService'
2
+ import { ResponseApi } from '@/api/types/Api_Service'
3
+ import {
4
+ Api_Video_Source_By_Repair,
5
+ Api_Video_Source_Create,
6
+ Api_Video_Source_Search,
7
+ Api_Work_Zone,
8
+ Api_Work_Zone_Search,
9
+ } from '@/api/types/Api_Video'
10
+
11
+ class VideoService extends ApiService {
12
+ public async startVideoAnalytics(): Promise<boolean> {
13
+ return await this.post('/statanly/start', null)
14
+ }
15
+
16
+ public reloadVideoAnalytics(ids: string[]): Promise<any> {
17
+ return this.post('/horizon/video-source/reload', { video_source_ids: ids })
18
+ }
19
+
20
+ public hardReloadStream(): Promise<any> {
21
+ return this.post('horizon/video-source/streams/add', null)
22
+ }
23
+
24
+ public async fetchWorkZones(params?: any): Promise<ResponseApi<Api_Work_Zone_Search[]>> {
25
+ return await this.get('/search/work_zones', { params })
26
+ }
27
+
28
+ public async fetchWorkZone(id: string): Promise<ResponseApi<Api_Work_Zone>> {
29
+ return await this.get(`/work_zone/get_work_zone/${id}`)
30
+ }
31
+
32
+ public async editWorkZone(id: string, body: { title: string }): Promise<{ data: Api_Work_Zone; status: number }> {
33
+ return await this.put(`/admin/work-zones/${id}`, body)
34
+ }
35
+
36
+ public async deleteWorkZone(id: string): Promise<{ data: boolean; status: number }> {
37
+ return await this.delete(`/admin/work-zones/${id}`)
38
+ }
39
+
40
+ public async fetchVideoSources(params?: any): Promise<ResponseApi<Api_Video_Source_Search[]>> {
41
+ return await this.get('/search/video_sources', { params })
42
+ }
43
+
44
+ public async createVideoSource(
45
+ body: Api_Video_Source_Create,
46
+ ): Promise<{ data: Api_Video_Source_Search; status: number }> {
47
+ return await this.post('horizon/video-source', body)
48
+ }
49
+
50
+ public async editVideoSource(
51
+ id: string,
52
+ body: Partial<Api_Video_Source_Create>,
53
+ ): Promise<{ data: Api_Video_Source_Search; status: number }> {
54
+ return await this.put(`/horizon/video-source/${id}`, body)
55
+ }
56
+
57
+ public async deleteVideoSource(id: string): Promise<void> {
58
+ await this.delete(`/horizon/video-source/${id}`)
59
+ }
60
+
61
+ public async fetchListRepairsVideoSource(params?: any): Promise<Api_Video_Source_By_Repair[]> {
62
+ return await this.get('work_zone/get_list_video_source_by_repair', { params })
63
+ }
64
+ }
65
+
66
+ let api: VideoService
67
+
68
+ export default function useVideoService() {
69
+ if (!api) api = new VideoService()
70
+ return api
71
+ }
@@ -1,124 +1,124 @@
1
- import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
-
3
- export enum ApiServiceType {
4
- SERVICE_AUTH = 'SERVICE_AUTH',
5
- }
6
-
7
- export default class ApiService {
8
- private axiosInstance: AxiosInstance
9
-
10
- constructor() {
11
- this.axiosInstance = axios.create({
12
- baseURL: process.env.VUE_APP_BACKEND,
13
- headers: {
14
- 'Content-Type': 'application/json',
15
- Accept: 'application/json',
16
- },
17
- })
18
-
19
- this.axiosInstance.interceptors.request.use(
20
- (config: InternalAxiosRequestConfig) => {
21
- const token = this.getToken()
22
- if (token && config.headers) {
23
- config.headers.Authorization = `Bearer ${token}`
24
- }
25
- return config
26
- },
27
- (error: AxiosError) => {
28
- return Promise.reject(error)
29
- },
30
- )
31
-
32
- this.axiosInstance.interceptors.response.use(
33
- (response: AxiosResponse) => {
34
- return response.data
35
- },
36
- (error: AxiosError) => {
37
- if (error.response?.status === 401 || error.response?.status === 403) {
38
- this.logout()
39
- }
40
- return Promise.reject(error)
41
- },
42
- )
43
- }
44
-
45
- private getToken() {
46
- return localStorage.getItem('token')
47
- }
48
-
49
- private removeToken() {
50
- localStorage.removeItem('token')
51
- }
52
-
53
- public logout(): void {
54
- this.removeToken()
55
- window.location.href = '/sign-in'
56
- }
57
-
58
- private handleError(error: AxiosError): void {
59
- if (error.response) {
60
- console.error('API Error:', error.response.status, error.response.data)
61
- } else if (error.request) {
62
- console.error('No response received:', error.request)
63
- } else {
64
- console.error('Error during request setup:', error.message)
65
- }
66
- }
67
-
68
- protected async get<T>(url: string, options?: AxiosRequestConfig) {
69
- try {
70
- const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
71
- if (response?.data === false) return false as unknown as T
72
-
73
- return response?.data ?? (response as unknown as T)
74
- } catch (error) {
75
- const axiosError = error as AxiosError
76
- this.handleError(axiosError)
77
- throw error
78
- }
79
- }
80
-
81
- protected async delete<T>(url: string, options?: AxiosRequestConfig) {
82
- try {
83
- return await this.axiosInstance.delete<T>(url, options)
84
- } catch (error) {
85
- const axiosError = error as AxiosError
86
- this.handleError(axiosError)
87
- throw error
88
- }
89
- }
90
-
91
- protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
92
- try {
93
- const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
94
- if (response?.data === false) return false
95
- return response?.data || (response as any)
96
- } catch (error) {
97
- const axiosError = error as AxiosError
98
- this.handleError(axiosError)
99
- throw error
100
- }
101
- }
102
-
103
- protected async patch<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig): Promise<T2> {
104
- try {
105
- const response: AxiosResponse<T2> = await this.axiosInstance.patch<T1, AxiosResponse<T2>>(url, payload, options)
106
- return response.data
107
- } catch (error) {
108
- const axiosError = error as AxiosError
109
- this.handleError(axiosError)
110
- throw error
111
- }
112
- }
113
-
114
- protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
115
- try {
116
- const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
117
- return response.data
118
- } catch (error) {
119
- const axiosError = error as AxiosError
120
- this.handleError(axiosError)
121
- throw error
122
- }
123
- }
124
- }
1
+ import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
+
3
+ export enum ApiServiceType {
4
+ SERVICE_AUTH = 'SERVICE_AUTH',
5
+ }
6
+
7
+ export default class ApiService {
8
+ private axiosInstance: AxiosInstance
9
+
10
+ constructor() {
11
+ this.axiosInstance = axios.create({
12
+ baseURL: process.env.VUE_APP_BACKEND,
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ Accept: 'application/json',
16
+ },
17
+ })
18
+
19
+ this.axiosInstance.interceptors.request.use(
20
+ (config: InternalAxiosRequestConfig) => {
21
+ const token = this.getToken()
22
+ if (token && config.headers) {
23
+ config.headers.Authorization = `Bearer ${token}`
24
+ }
25
+ return config
26
+ },
27
+ (error: AxiosError) => {
28
+ return Promise.reject(error)
29
+ },
30
+ )
31
+
32
+ this.axiosInstance.interceptors.response.use(
33
+ (response: AxiosResponse) => {
34
+ return response.data
35
+ },
36
+ (error: AxiosError) => {
37
+ if (error.response?.status === 401 || error.response?.status === 403) {
38
+ this.logout()
39
+ }
40
+ return Promise.reject(error)
41
+ },
42
+ )
43
+ }
44
+
45
+ private getToken() {
46
+ return localStorage.getItem('token')
47
+ }
48
+
49
+ private removeToken() {
50
+ localStorage.removeItem('token')
51
+ }
52
+
53
+ public logout(): void {
54
+ this.removeToken()
55
+ window.location.href = '/sign-in'
56
+ }
57
+
58
+ private handleError(error: AxiosError): void {
59
+ if (error.response) {
60
+ console.error('API Error:', error.response.status, error.response.data)
61
+ } else if (error.request) {
62
+ console.error('No response received:', error.request)
63
+ } else {
64
+ console.error('Error during request setup:', error.message)
65
+ }
66
+ }
67
+
68
+ protected async get<T>(url: string, options?: AxiosRequestConfig) {
69
+ try {
70
+ const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
71
+ if (response?.data === false) return false as unknown as T
72
+
73
+ return response?.data ?? (response as unknown as T)
74
+ } catch (error) {
75
+ const axiosError = error as AxiosError
76
+ this.handleError(axiosError)
77
+ throw error
78
+ }
79
+ }
80
+
81
+ protected async delete<T>(url: string, options?: AxiosRequestConfig) {
82
+ try {
83
+ return await this.axiosInstance.delete<T>(url, options)
84
+ } catch (error) {
85
+ const axiosError = error as AxiosError
86
+ this.handleError(axiosError)
87
+ throw error
88
+ }
89
+ }
90
+
91
+ protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
92
+ try {
93
+ const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
94
+ if (response?.data === false) return false
95
+ return response?.data || (response as any)
96
+ } catch (error) {
97
+ const axiosError = error as AxiosError
98
+ this.handleError(axiosError)
99
+ throw error
100
+ }
101
+ }
102
+
103
+ protected async patch<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig): Promise<T2> {
104
+ try {
105
+ const response: AxiosResponse<T2> = await this.axiosInstance.patch<T1, AxiosResponse<T2>>(url, payload, options)
106
+ return response.data
107
+ } catch (error) {
108
+ const axiosError = error as AxiosError
109
+ this.handleError(axiosError)
110
+ throw error
111
+ }
112
+ }
113
+
114
+ protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
115
+ try {
116
+ const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
117
+ return response.data
118
+ } catch (error) {
119
+ const axiosError = error as AxiosError
120
+ this.handleError(axiosError)
121
+ throw error
122
+ }
123
+ }
124
+ }