| 1 | import type { FlaskBaseResponse } from "@/types/flask.d" |
| 2 | import type { ExclusionRule } from "@/types/incidentManagement/exclusionRules.d" |
| 3 | import { HttpClient } from "../../httpClient" |
| 4 | |
| 5 | export interface ExclusionRulesQuery { |
| 6 | pagination: { |
| 7 | skip?: number |
| 8 | limit?: number |
| 9 | } |
| 10 | filters: { |
| 11 | enabledOnly?: boolean |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | export interface ExclusionRulePayload { |
| 16 | name: string |
| 17 | description: string |
| 18 | channel: string |
| 19 | title: string |
| 20 | field_matches: { [key: string]: string } |
| 21 | enabled: boolean |
| 22 | customer_code?: string |
| 23 | } |
| 24 | |
| 25 | export default { |
| 26 | getExclusionRulesList(args: Partial<ExclusionRulesQuery>, signal?: AbortSignal) { |
| 27 | // TODO-FE: remove any |
| 28 | const params: any = { |
| 29 | skip: args.pagination?.skip || 0, |
| 30 | limit: args.pagination?.limit || 25 |
| 31 | } |
| 32 | |
| 33 | if (args.filters?.enabledOnly !== undefined) { |
| 34 | params.enabled_only = args.filters.enabledOnly |
| 35 | } |
| 36 | |
| 37 | return HttpClient.get< |
| 38 | FlaskBaseResponse & { |
| 39 | exclusions: ExclusionRule[] |
| 40 | pagination: { |
| 41 | total: number |
| 42 | skip: number |
| 43 | limit: number |
| 44 | } |
| 45 | } |
| 46 | >(`/incidents/alerts/create/velo-sigma/exclusion`, { params, signal }) |
| 47 | }, |
| 48 | createExclusionRule(payload: ExclusionRulePayload) { |
| 49 | return HttpClient.post<FlaskBaseResponse & { exclusion_response: ExclusionRule }>( |
| 50 | `/incidents/alerts/create/velo-sigma/exclusion`, |
| 51 | payload |
| 52 | ) |
| 53 | }, |
| 54 | updateExclusionRule(exclusionId: number, payload: ExclusionRulePayload) { |
| 55 | return HttpClient.patch<FlaskBaseResponse & { exclusion_response: ExclusionRule }>( |
| 56 | `/incidents/alerts/create/velo-sigma/exclusion/${exclusionId}`, |
| 57 | payload |
| 58 | ) |
| 59 | }, |
| 60 | toggleExclusionRuleStatus(exclusionId: number) { |
| 61 | return HttpClient.post<FlaskBaseResponse & { exclusion_response: ExclusionRule }>( |
| 62 | `/incidents/alerts/velo-sigma/exclusion/${exclusionId}/toggle` |
| 63 | ) |
| 64 | }, |
| 65 | deleteExclusionRules(exclusionId: number) { |
| 66 | return HttpClient.delete<FlaskBaseResponse>(`/incidents/alerts/create/velo-sigma/exclusion/${exclusionId}`) |
| 67 | } |
| 68 | } |