graphicek/client/src/api/alerts.ts

38 lines
926 B
TypeScript
Raw Normal View History

2024-03-29 21:42:09 +01:00
import { request } from './request'
export type AlertInfo = {
id: number
name: string
condition: string
contactPointId: number
customMessage: string
2024-03-31 20:47:43 +02:00
customResolvedMessage: string
2024-03-29 21:42:09 +01:00
triggerInterval: number
lastStatus: string
lastStatusAt: string
}
export const getAlerts = () => request<AlertInfo[]>('/api/alerts')
2024-03-31 09:50:09 +02:00
export const createAlert = (
data: Omit<AlertInfo, 'id' | 'lastStatus' | 'lastStatusAt'>
) =>
2024-03-29 21:42:09 +01:00
request<AlertInfo>('/api/alerts', {
method: 'POST',
headers: { 'content-type': 'application/json' },
2024-03-31 09:50:09 +02:00
body: JSON.stringify(data),
2024-03-29 21:42:09 +01:00
})
2024-03-31 09:50:09 +02:00
export const updateAlert = ({
id,
...body
}: Omit<AlertInfo, 'lastStatus' | 'lastStatusAt'>) =>
2024-03-29 21:42:09 +01:00
request<AlertInfo>(`/api/alerts/${id}`, {
method: 'PUT',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(body),
})
export const deleteAlert = (id: number) =>
request<AlertInfo, 'void'>(`/api/alerts/${id}`, { method: 'DELETE' }, 'void')