main
ts 220 lines 5.88 KB
Raw
1 import type { Case, CaseDataStoreFile, CasesFilters, CasesListResponse, CaseStatus } from "@/types/cases"
2 import type { CommentItem } from "@/types/comments"
3 import type { CommonResponse, Pagination } from "@/types/common"
4 import { HttpClient } from "../httpClient"
5 import { withCustomerCodes } from "../params"
6
7 export interface CasePayload {
8 case_name: string
9 case_status: CaseStatus
10 case_description: string
11 assigned_to?: string
12 customer_code?: string
13 }
14
15 export interface CaseCommentPayload {
16 caseId: number
17 comment: string
18 userName: string
19 commentId?: number
20 }
21
22 export default {
23 /**
24 * Get all cases with customer access control
25 */
26 getCases({ page = 1, pageSize = 25, order = "desc" }: Pagination, signal?: AbortSignal, customerCodes?: string[]) {
27 return HttpClient.get<CommonResponse<CasesListResponse>>(
28 "/incidents/db_operations/cases",
29 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
30 )
31 },
32
33 /**
34 * Get specific case by ID (with customer access validation)
35 */
36 getCase(caseId: number) {
37 return HttpClient.get<CommonResponse<CasesListResponse>>(`/incidents/db_operations/case/${caseId}`)
38 },
39
40 /**
41 * Update case status (customer access controlled)
42 */
43 updateCaseStatus(caseId: number, status: CaseStatus) {
44 return HttpClient.put<CommonResponse<{ case: Case }>>(`/incidents/db_operations/case/status`, {
45 case_id: caseId,
46 status
47 })
48 },
49
50 /**
51 * Update case assigned user (customer access controlled)
52 */
53 updateCaseAssignedTo(caseId: number, assignedTo: string) {
54 return HttpClient.put<CommonResponse<{ case: Case }>>(`/incidents/db_operations/case/assigned-to`, {
55 case_id: caseId,
56 assigned_to: assignedTo
57 })
58 },
59
60 /**
61 * Create new case (customer access controlled)
62 */
63 createCase(payload: CasePayload) {
64 return HttpClient.post<CommonResponse<{ case: Case }>>(`/incidents/db_operations/case/create`, {
65 ...payload,
66 case_creation_time: new Date().toISOString()
67 })
68 },
69
70 /**
71 * Delete case (customer access controlled)
72 */
73 deleteCase(caseId: number) {
74 return HttpClient.delete<CommonResponse>(`/incidents/db_operations/case/${caseId}`)
75 },
76
77 /**
78 * Get cases by status with customer filtering
79 */
80 getCasesByStatus(
81 status: CaseStatus,
82 { page = 1, pageSize = 25, order = "desc" }: Pagination,
83 signal?: AbortSignal,
84 customerCodes?: string[]
85 ) {
86 return HttpClient.get<CommonResponse<CasesListResponse>>(
87 `/incidents/db_operations/case/status/${status}`,
88 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
89 )
90 },
91
92 /**
93 * Get cases by assigned user with customer filtering
94 */
95 getCasesByAssignedTo(
96 assignedTo: string,
97 { page = 1, pageSize = 25, order = "desc" }: Pagination,
98 signal?: AbortSignal,
99 customerCodes?: string[]
100 ) {
101 return HttpClient.get<CommonResponse<CasesListResponse>>(
102 `/incidents/db_operations/case/assigned-to/${assignedTo}`,
103 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
104 )
105 },
106
107 /**
108 * Create case from alert (customer access controlled)
109 */
110 createCaseFromAlert(alertId: number) {
111 return HttpClient.post<CommonResponse<{ case_alert_link: { case_id: number; alert_id: number } }>>(
112 `/incidents/db_operations/case/from-alert`,
113 {
114 alert_id: alertId
115 }
116 )
117 },
118
119 /**
120 * Link case to alert (customer access controlled)
121 */
122 linkCaseToAlert(caseId: number, alertId: number) {
123 return HttpClient.post<CommonResponse<{ case_alert_link: { case_id: number; alert_id: number } }>>(
124 `/incidents/db_operations/case/alert-link`,
125 {
126 case_id: caseId,
127 alert_id: alertId
128 }
129 )
130 },
131
132 /**
133 * Unlink case from alert (customer access controlled)
134 */
135 unlinkCaseFromAlert(caseId: number, alertId: number) {
136 return HttpClient.post<CommonResponse>(`/incidents/db_operations/case/alert-unlink`, {
137 case_id: caseId,
138 alert_id: alertId
139 })
140 },
141
142 /**
143 * Create a new case comment
144 */
145 addComment(payload: CaseCommentPayload) {
146 return HttpClient.post<CommonResponse<{ comment: CommentItem }>>(`/incidents/db_operations/case/comment`, {
147 comment: payload.comment,
148 case_id: payload.caseId,
149 user_name: payload.userName
150 })
151 },
152
153 /**
154 * Update an existing case comment
155 */
156 updateComment(payload: CaseCommentPayload) {
157 return HttpClient.put<CommonResponse<{ comment: CommentItem }>>(`/incidents/db_operations/case/comment`, {
158 comment_id: payload.commentId,
159 case_id: payload.caseId,
160 comment: payload.comment,
161 user_name: payload.userName,
162 created_at: new Date().toISOString()
163 })
164 },
165
166 /**
167 * Delete a case comment
168 */
169 deleteComment(commentId: number) {
170 return HttpClient.delete<CommonResponse>(`/incidents/db_operations/case/comment/${commentId}`)
171 },
172
173 /**
174 * Get files associated with a specific case
175 */
176 getCaseFiles(caseId: number) {
177 return HttpClient.get<CommonResponse<{ case_data_store: CaseDataStoreFile[] }>>(
178 `/incidents/db_operations/case/data-store/${caseId}`
179 )
180 },
181
182 /**
183 * Download a specific file from a case
184 * Returns the blob data for download
185 */
186 downloadCaseFile(caseId: number, fileName: string) {
187 return HttpClient.get<Blob>(`/incidents/db_operations/case/data-store/download/${caseId}/${fileName}`, {
188 responseType: "blob"
189 })
190 },
191
192 /**
193 * Upload a file to a case data store
194 */
195 uploadCaseFile(caseId: number, file: File) {
196 return HttpClient.postForm<CommonResponse<{ case_data_store: CaseDataStoreFile[] }>>(
197 `/incidents/db_operations/case/data-store/upload?case_id=${caseId}`,
198 { file },
199 {
200 headers: {
201 "Content-Type": "multipart/form-data"
202 }
203 }
204 )
205 },
206
207 /**
208 * Delete a file from a case data store
209 */
210 deleteCaseFile(caseId: number, fileName: string) {
211 return HttpClient.delete<CommonResponse>(`/incidents/db_operations/case/data-store/${caseId}/${fileName}`)
212 },
213
214 /**
215 * Get cases filter options
216 */
217 getCasesFilters() {
218 return HttpClient.get<CommonResponse<CasesFilters>>("/incidents/db_operations/cases/filter-options")
219 }
220 }