50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { fetchWithAuth } from "./client";
|
|
|
|
function buildQuery(params: Record<string, string | number | boolean | undefined>): string {
|
|
const qs = Object.entries(params)
|
|
.filter(([, v]) => v !== undefined)
|
|
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
.join("&");
|
|
return qs ? `?${qs}` : "";
|
|
}
|
|
|
|
export const alertsApi = {
|
|
/** 获取未读告警数量 */
|
|
getUnreadCount: (token: string) =>
|
|
fetchWithAuth("/api/v1/alerts/unread-count", {}, token),
|
|
|
|
/** 获取告警列表 */
|
|
getAlerts: (
|
|
token: string,
|
|
params?: { limit?: number; offset?: number; is_read?: boolean }
|
|
) => fetchWithAuth(`/api/v1/alerts/${buildQuery(params || {})}`, {}, token),
|
|
|
|
/** 标记单条告警已读 */
|
|
markRead: (token: string, alertId: string) =>
|
|
fetchWithAuth(`/api/v1/alerts/${alertId}/read`, { method: "POST" }, token),
|
|
|
|
/** 标记所有告警已读 */
|
|
markAllRead: (token: string) =>
|
|
fetchWithAuth("/api/v1/alerts/read-all", { method: "POST" }, token),
|
|
|
|
/** 获取告警设置 */
|
|
getSettings: (token: string, brandId: string) =>
|
|
fetchWithAuth(`/api/v1/alerts/settings?brand_id=${encodeURIComponent(brandId)}`, {}, token),
|
|
|
|
/** 更新告警设置 */
|
|
updateSettings: (
|
|
token: string,
|
|
data: Array<{
|
|
brand_id: string;
|
|
alert_type: string;
|
|
enabled: boolean;
|
|
threshold?: number;
|
|
}>
|
|
) =>
|
|
fetchWithAuth(
|
|
"/api/v1/alerts/settings",
|
|
{ method: "PUT", body: JSON.stringify(data) },
|
|
token
|
|
),
|
|
};
|