main
ts 139 lines 3.99 KB
Raw
1 import type { Alert, AlertsFilters, AlertsListResponse, AlertStatus } from "@/types/alerts"
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 AlertCommentPayload {
8 alertId: number
9 comment: string
10 userName: string
11 commentId?: number
12 }
13
14 export default {
15 /**
16 * Get all alerts with customer access control
17 */
18 getAlerts({ page = 1, pageSize = 25, order = "desc" }: Pagination, signal?: AbortSignal, customerCodes?: string[]) {
19 return HttpClient.get<CommonResponse<AlertsListResponse>>(
20 "/incidents/db_operations/alerts",
21 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
22 )
23 },
24
25 /**
26 * Get specific alert by ID (with customer access validation)
27 */
28 getAlert(alertId: number) {
29 return HttpClient.get<CommonResponse<AlertsListResponse>>(`/incidents/db_operations/alert/${alertId}`)
30 },
31
32 /**
33 * Update alert status (customer access controlled)
34 */
35 updateAlertStatus(alertId: number, status: AlertStatus) {
36 return HttpClient.put<CommonResponse<{ alerts: Alert[] }>>(`/incidents/db_operations/alert/status`, {
37 alert_id: alertId,
38 status
39 })
40 },
41
42 /**
43 * Add comment to alert (customer access controlled)
44 */
45 addComment(payload: AlertCommentPayload) {
46 return HttpClient.post<CommonResponse<{ comment: CommentItem }>>(`/incidents/db_operations/alert/comment`, {
47 alert_id: payload.alertId,
48 comment: payload.comment,
49 user_name: payload.userName
50 })
51 },
52
53 /**
54 * Update an existing alert comment
55 */
56 updateComment(payload: AlertCommentPayload) {
57 return HttpClient.put<CommonResponse<{ comment: CommentItem }>>(`/incidents/db_operations/alert/comment`, {
58 comment_id: payload.commentId,
59 alert_id: payload.alertId,
60 comment: payload.comment,
61 user_name: payload.userName,
62 created_at: new Date().toISOString()
63 })
64 },
65
66 /**
67 * Delete alert comment (customer access controlled)
68 */
69 deleteComment(commentId: number) {
70 return HttpClient.delete<CommonResponse>(`/incidents/db_operations/alert/comment/${commentId}`)
71 },
72
73 /**
74 * Get alerts by status with customer filtering
75 */
76 getAlertsByStatus(
77 status: AlertStatus,
78 { page = 1, pageSize = 25, order = "desc" }: Pagination,
79 signal?: AbortSignal,
80 customerCodes?: string[]
81 ) {
82 return HttpClient.get<CommonResponse<AlertsListResponse>>(
83 `/incidents/db_operations/alerts/status/${status}`,
84 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
85 )
86 },
87
88 /**
89 * Get alerts by asset name with customer filtering
90 */
91 getAlertsByAsset(
92 assetName: string,
93 { page = 1, pageSize = 25, order = "desc" }: Pagination,
94 signal?: AbortSignal,
95 customerCodes?: string[]
96 ) {
97 return HttpClient.get<CommonResponse<AlertsListResponse>>(
98 `/incidents/db_operations/alerts/asset/${assetName}`,
99 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
100 )
101 },
102
103 /**
104 * Get alerts by tag with customer filtering
105 */
106 getAlertsByTag(
107 tag: string,
108 { page = 1, pageSize = 25, order = "desc" }: Pagination,
109 signal?: AbortSignal,
110 customerCodes?: string[]
111 ) {
112 return HttpClient.get<CommonResponse<AlertsListResponse>>(
113 `/incidents/db_operations/alert/tag/${tag}`,
114 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
115 )
116 },
117
118 /**
119 * Get alerts by source with customer filtering
120 */
121 getAlertsBySource(
122 source: string,
123 { page = 1, pageSize = 25, order = "desc" }: Pagination,
124 signal?: AbortSignal,
125 customerCodes?: string[]
126 ) {
127 return HttpClient.get<CommonResponse<AlertsListResponse>>(
128 `/incidents/db_operations/alerts/source/${source}`,
129 withCustomerCodes(customerCodes, { params: { page, page_size: pageSize, order }, signal })
130 )
131 },
132
133 /**
134 * Get alerts filter options
135 */
136 getAlertsFilters() {
137 return HttpClient.get<CommonResponse<AlertsFilters>>(`/incidents/db_operations/alerts/filter-options`)
138 }
139 }