feat(admin): 增加审计与一致性页面
This commit is contained in:
46
apps/web/lib/consistency-api.ts
Normal file
46
apps/web/lib/consistency-api.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { api } from './api';
|
||||
|
||||
export type ConsistencySeverity = 'ok' | 'warn' | 'error';
|
||||
export type ConsistencyStatus = 'pass' | 'fail';
|
||||
|
||||
export interface ConsistencyCheckResult {
|
||||
id: string;
|
||||
label: string;
|
||||
severity: ConsistencySeverity;
|
||||
count: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface ConsistencyResult {
|
||||
generatedAt: string;
|
||||
status: ConsistencyStatus;
|
||||
counts: Record<string, number>;
|
||||
checks: {
|
||||
partitionKeys: ConsistencyCheckResult[];
|
||||
orphanReferences: ConsistencyCheckResult[];
|
||||
auditCoverage: ConsistencyCheckResult[];
|
||||
};
|
||||
summary: {
|
||||
errors: number;
|
||||
warnings: number;
|
||||
human: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function getConsistencyReport() {
|
||||
return api.get<ConsistencyResult>('/consistency');
|
||||
}
|
||||
|
||||
export function summarizeConsistencyResult(result: ConsistencyResult) {
|
||||
const checks = [
|
||||
...result.checks.partitionKeys,
|
||||
...result.checks.orphanReferences,
|
||||
...result.checks.auditCoverage,
|
||||
];
|
||||
return {
|
||||
ok: checks.filter((item) => item.severity === 'ok').length,
|
||||
warn: checks.filter((item) => item.severity === 'warn').length,
|
||||
error: checks.filter((item) => item.severity === 'error').length,
|
||||
total: checks.length,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user