graphicek/client/src/api/alerts.ts

32 lines
817 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
triggerInterval: number
lastStatus: string
lastStatusAt: string
}
export const getAlerts = () => request<AlertInfo[]>('/api/alerts')
export const createAlert = (data: Omit<AlertInfo, 'id'>) =>
request<AlertInfo>('/api/alerts', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ data }),
})
export const updateAlert = ({ id, ...body }: AlertInfo) =>
request<AlertInfo>(`/api/alerts/${id}`, {
method: 'PUT',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(body),
})
export const deleteAlert = (id: number) =>
request<AlertInfo>(`/api/alerts/${id}`, { method: 'DELETE' }, 'void')