文件
hyb-oa/client/src/api/audit.ts
T

51 行
1.1 KiB
TypeScript

import { apiRequestData } from "./http";
export type AuditLogItem = {
id: string;
requestId: string;
actorId: string;
actorName: string;
actorEmail: string;
action: string;
targetType: string;
targetId: string | null;
ipAddress: string | null;
userAgent: string | null;
extra: Record<string, unknown>;
createdAt: string;
};
export type AuditLogListResponse = {
page: number;
pageSize: number;
total: number;
items: AuditLogItem[];
};
export type AuditLogQuery = {
page?: number;
pageSize?: number;
actorId?: string;
action?: string;
targetType?: string;
dateFrom?: string;
dateTo?: string;
};
function toQueryString(query: AuditLogQuery) {
const params = new URLSearchParams();
for (const [key, value] of Object.entries(query)) {
if (value == null || value === "") {
continue;
}
params.set(key, String(value));
}
const encoded = params.toString();
return encoded ? `?${encoded}` : "";
}
export async function fetchAuditLogs(query: AuditLogQuery) {
return apiRequestData<AuditLogListResponse>(`/api/audit-logs${toQueryString(query)}`);
}