refactor(web): alerts + deviceReadings API 迁移为对象风格导出
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- alerts.ts: listAlerts → alertApi.list, acknowledgeAlert → alertApi.acknowledge 等
- deviceReadings.ts: batchCreateReadings → deviceReadingApi.batchCreate 等
- AlertList/AlertRuleList 引用处同步更新
- 其余 19 个函数式 API 文件记为待迁移(旧文件不强制迁移)
This commit is contained in:
iven
2026-04-28 19:47:48 +08:00
parent 99093d8143
commit e5546efa41
4 changed files with 42 additions and 83 deletions

View File

@@ -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),
};

View File

@@ -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>);
},
};