refactor(web): alerts + deviceReadings API 迁移为对象风格导出
- alerts.ts: listAlerts → alertApi.list, acknowledgeAlert → alertApi.acknowledge 等 - deviceReadings.ts: batchCreateReadings → deviceReadingApi.batchCreate 等 - AlertList/AlertRuleList 引用处同步更新 - 其余 19 个函数式 API 文件记为待迁移(旧文件不强制迁移)
This commit is contained in:
@@ -57,53 +57,31 @@ export interface UpdateAlertRuleReq {
|
||||
version: number;
|
||||
}
|
||||
|
||||
// --- Alert API ---
|
||||
export async function listAlerts(params?: {
|
||||
patient_id?: string;
|
||||
status?: string;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}) {
|
||||
const res = await client.get('/health/alerts', { params });
|
||||
return res.data.data as PaginatedResponse<Alert>;
|
||||
}
|
||||
// --- API ---
|
||||
export const alertApi = {
|
||||
list: (params?: { patient_id?: string; status?: string; page?: number; page_size?: number }) =>
|
||||
client.get('/health/alerts', { params }).then((r) => r.data.data as PaginatedResponse<Alert>),
|
||||
|
||||
export async function acknowledgeAlert(id: string, version: number) {
|
||||
const res = await client.put(`/health/alerts/${id}/acknowledge`, { version });
|
||||
return res.data.data as Alert;
|
||||
}
|
||||
acknowledge: (id: string, version: number) =>
|
||||
client.put(`/health/alerts/${id}/acknowledge`, { version }).then((r) => r.data.data as Alert),
|
||||
|
||||
export async function dismissAlert(id: string, version: number) {
|
||||
const res = await client.put(`/health/alerts/${id}/dismiss`, { version });
|
||||
return res.data.data as Alert;
|
||||
}
|
||||
dismiss: (id: string, version: number) =>
|
||||
client.put(`/health/alerts/${id}/dismiss`, { version }).then((r) => r.data.data as Alert),
|
||||
|
||||
export async function resolveAlert(id: string, version: number) {
|
||||
const res = await client.put(`/health/alerts/${id}/resolve`, { version });
|
||||
return res.data.data as Alert;
|
||||
}
|
||||
resolve: (id: string, version: number) =>
|
||||
client.put(`/health/alerts/${id}/resolve`, { version }).then((r) => r.data.data as Alert),
|
||||
};
|
||||
|
||||
// --- Alert Rule API ---
|
||||
export async function listAlertRules(params?: {
|
||||
device_type?: string;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}) {
|
||||
const res = await client.get('/health/alert-rules', { params });
|
||||
return res.data.data as PaginatedResponse<AlertRule>;
|
||||
}
|
||||
export const alertRuleApi = {
|
||||
list: (params?: { device_type?: string; page?: number; page_size?: number }) =>
|
||||
client.get('/health/alert-rules', { params }).then((r) => r.data.data as PaginatedResponse<AlertRule>),
|
||||
|
||||
export async function createAlertRule(data: CreateAlertRuleReq) {
|
||||
const res = await client.post('/health/alert-rules', data);
|
||||
return res.data.data as AlertRule;
|
||||
}
|
||||
create: (data: CreateAlertRuleReq) =>
|
||||
client.post('/health/alert-rules', data).then((r) => r.data.data as AlertRule),
|
||||
|
||||
export async function updateAlertRule(id: string, data: UpdateAlertRuleReq) {
|
||||
const res = await client.put(`/health/alert-rules/${id}`, data);
|
||||
return res.data.data as AlertRule;
|
||||
}
|
||||
update: (id: string, data: UpdateAlertRuleReq) =>
|
||||
client.put(`/health/alert-rules/${id}`, data).then((r) => r.data.data as AlertRule),
|
||||
|
||||
export async function deactivateAlertRule(id: string, version: number) {
|
||||
const res = await client.put(`/health/alert-rules/${id}/deactivate`, { version });
|
||||
return res.data.data as AlertRule;
|
||||
}
|
||||
deactivate: (id: string, version: number) =>
|
||||
client.put(`/health/alert-rules/${id}/deactivate`, { version }).then((r) => r.data.data as AlertRule),
|
||||
};
|
||||
|
||||
@@ -40,31 +40,17 @@ export interface BatchResult {
|
||||
}
|
||||
|
||||
// --- API ---
|
||||
export async function batchCreateReadings(patientId: string, data: BatchReadingRequest) {
|
||||
const res = await client.post(`/health/patients/${patientId}/device-readings/batch`, data);
|
||||
return res.data.data as BatchResult;
|
||||
}
|
||||
export const deviceReadingApi = {
|
||||
batchCreate: (patientId: string, data: BatchReadingRequest) =>
|
||||
client.post(`/health/patients/${patientId}/device-readings/batch`, data).then((r) => r.data.data as BatchResult),
|
||||
|
||||
export async function queryReadings(params: {
|
||||
patient_id: string;
|
||||
device_type?: string;
|
||||
hours?: number;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}) {
|
||||
const { patient_id, ...query } = params;
|
||||
const res = await client.get(`/health/patients/${patient_id}/device-readings`, { params: query });
|
||||
return res.data.data as PaginatedResponse<DeviceReading>;
|
||||
}
|
||||
query: (params: { patient_id: string; device_type?: string; hours?: number; page?: number; page_size?: number }) => {
|
||||
const { patient_id, ...query } = params;
|
||||
return client.get(`/health/patients/${patient_id}/device-readings`, { params: query }).then((r) => r.data.data as PaginatedResponse<DeviceReading>);
|
||||
},
|
||||
|
||||
export async function queryHourlyReadings(params: {
|
||||
patient_id: string;
|
||||
device_type: string;
|
||||
days?: number;
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
}) {
|
||||
const { patient_id, ...query } = params;
|
||||
const res = await client.get(`/health/patients/${patient_id}/device-readings/hourly`, { params: query });
|
||||
return res.data.data as PaginatedResponse<HourlyReading>;
|
||||
}
|
||||
queryHourly: (params: { patient_id: string; device_type: string; days?: number; page?: number; page_size?: number }) => {
|
||||
const { patient_id, ...query } = params;
|
||||
return client.get(`/health/patients/${patient_id}/device-readings/hourly`, { params: query }).then((r) => r.data.data as PaginatedResponse<HourlyReading>);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,9 +14,7 @@ import {
|
||||
import { CheckOutlined, StopOutlined } from '@ant-design/icons';
|
||||
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
|
||||
import {
|
||||
listAlerts,
|
||||
acknowledgeAlert,
|
||||
dismissAlert,
|
||||
alertApi,
|
||||
type Alert,
|
||||
} from '../../api/health/alerts';
|
||||
import { AuthButton } from '../../components/AuthButton';
|
||||
@@ -110,7 +108,7 @@ export default function AlertList() {
|
||||
refresh,
|
||||
} = usePaginatedData<Alert, AlertFilters>(
|
||||
async (p, pageSize, f) => {
|
||||
const result = await listAlerts({
|
||||
const result = await alertApi.list({
|
||||
page: p,
|
||||
page_size: pageSize,
|
||||
status: f.status || undefined,
|
||||
@@ -146,7 +144,7 @@ export default function AlertList() {
|
||||
const handleAcknowledge = async (record: Alert) => {
|
||||
setActionLoading(record.id);
|
||||
try {
|
||||
await acknowledgeAlert(record.id, record.version);
|
||||
await alertApi.acknowledge(record.id, record.version);
|
||||
message.success('告警已确认');
|
||||
refresh();
|
||||
} catch {
|
||||
@@ -159,7 +157,7 @@ export default function AlertList() {
|
||||
const handleDismiss = async (record: Alert) => {
|
||||
setActionLoading(record.id);
|
||||
try {
|
||||
await dismissAlert(record.id, record.version);
|
||||
await alertApi.dismiss(record.id, record.version);
|
||||
message.success('告警已忽略');
|
||||
refresh();
|
||||
} catch {
|
||||
|
||||
@@ -3,10 +3,7 @@ import { Button, Form, Input, InputNumber, message, Modal, Select, Space, Switch
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
|
||||
import {
|
||||
createAlertRule,
|
||||
deactivateAlertRule,
|
||||
listAlertRules,
|
||||
updateAlertRule,
|
||||
alertRuleApi,
|
||||
type AlertRule,
|
||||
type CreateAlertRuleReq,
|
||||
type UpdateAlertRuleReq,
|
||||
@@ -53,7 +50,7 @@ export default function AlertRuleList() {
|
||||
const fetchRules = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await listAlertRules({ page, page_size: 20 });
|
||||
const res = await alertRuleApi.list({ page, page_size: 20 });
|
||||
setData(res.data);
|
||||
setTotal(res.total);
|
||||
} catch {
|
||||
@@ -105,7 +102,7 @@ export default function AlertRuleList() {
|
||||
cooldown_minutes: values.cooldown_minutes,
|
||||
version: editingRule.version,
|
||||
};
|
||||
await updateAlertRule(editingRule.id, req);
|
||||
await alertRuleApi.update(editingRule.id, req);
|
||||
message.success('规则已更新');
|
||||
} else {
|
||||
const req: CreateAlertRuleReq = {
|
||||
@@ -117,7 +114,7 @@ export default function AlertRuleList() {
|
||||
severity: values.severity,
|
||||
cooldown_minutes: values.cooldown_minutes,
|
||||
};
|
||||
await createAlertRule(req);
|
||||
await alertRuleApi.create(req);
|
||||
message.success('规则已创建');
|
||||
}
|
||||
setModalOpen(false);
|
||||
@@ -132,7 +129,7 @@ export default function AlertRuleList() {
|
||||
const handleToggle = async (rule: AlertRule, active: boolean) => {
|
||||
try {
|
||||
if (!active) {
|
||||
await deactivateAlertRule(rule.id, rule.version);
|
||||
await alertRuleApi.deactivate(rule.id, rule.version);
|
||||
message.success('规则已禁用');
|
||||
}
|
||||
fetchRules();
|
||||
|
||||
Reference in New Issue
Block a user