do to formatters
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import type { HealthDTO } from '@/lib/types/generated/HealthDTO';
|
||||
import type { HealthViewData, HealthStatus, HealthMetrics, HealthComponent, HealthAlert } from '@/lib/view-data/HealthViewData';
|
||||
import { HealthStatusDisplay } from '@/lib/display-objects/HealthStatusDisplay';
|
||||
import { HealthMetricDisplay } from '@/lib/display-objects/HealthMetricDisplay';
|
||||
import { HealthComponentDisplay } from '@/lib/display-objects/HealthComponentDisplay';
|
||||
import { HealthAlertDisplay } from '@/lib/display-objects/HealthAlertDisplay';
|
||||
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
|
||||
import { HealthAlertFormatter } from '@/lib/formatters/HealthAlertFormatter';
|
||||
import { HealthComponentFormatter } from '@/lib/formatters/HealthComponentFormatter';
|
||||
import { HealthMetricFormatter } from '@/lib/formatters/HealthMetricFormatter';
|
||||
import { HealthStatusFormatter } from '@/lib/formatters/HealthStatusFormatter';
|
||||
import type { HealthDTO } from '@/lib/types/generated/HealthDTO';
|
||||
import type { HealthAlert, HealthComponent, HealthMetrics, HealthStatus, HealthViewData } from '@/lib/view-data/HealthViewData';
|
||||
|
||||
export class HealthViewDataBuilder {
|
||||
public static build(apiDto: HealthDTO): HealthViewData {
|
||||
@@ -17,37 +17,37 @@ export class HealthViewDataBuilder {
|
||||
const overallStatus: HealthStatus = {
|
||||
status: apiDto.status,
|
||||
timestamp: apiDto.timestamp,
|
||||
formattedTimestamp: HealthStatusDisplay.formatTimestamp(apiDto.timestamp),
|
||||
relativeTime: HealthStatusDisplay.formatRelativeTime(apiDto.timestamp),
|
||||
statusLabel: HealthStatusDisplay.formatStatusLabel(apiDto.status),
|
||||
statusColor: HealthStatusDisplay.formatStatusColor(apiDto.status),
|
||||
statusIcon: HealthStatusDisplay.formatStatusIcon(apiDto.status),
|
||||
formattedTimestamp: HealthStatusFormatter.formatTimestamp(apiDto.timestamp),
|
||||
relativeTime: HealthStatusFormatter.formatRelativeTime(apiDto.timestamp),
|
||||
statusLabel: HealthStatusFormatter.formatStatusLabel(apiDto.status),
|
||||
statusColor: HealthStatusFormatter.formatStatusColor(apiDto.status),
|
||||
statusIcon: HealthStatusFormatter.formatStatusIcon(apiDto.status),
|
||||
};
|
||||
|
||||
// Build metrics
|
||||
const metrics: HealthMetrics = {
|
||||
uptime: HealthMetricDisplay.formatUptime(apiDto.uptime),
|
||||
responseTime: HealthMetricDisplay.formatResponseTime(apiDto.responseTime),
|
||||
errorRate: HealthMetricDisplay.formatErrorRate(apiDto.errorRate),
|
||||
uptime: HealthMetricFormatter.formatUptime(apiDto.uptime),
|
||||
responseTime: HealthMetricFormatter.formatResponseTime(apiDto.responseTime),
|
||||
errorRate: HealthMetricFormatter.formatErrorRate(apiDto.errorRate),
|
||||
lastCheck: apiDto.lastCheck || lastUpdated,
|
||||
formattedLastCheck: HealthMetricDisplay.formatTimestamp(apiDto.lastCheck || lastUpdated),
|
||||
formattedLastCheck: HealthMetricFormatter.formatTimestamp(apiDto.lastCheck || lastUpdated),
|
||||
checksPassed: apiDto.checksPassed || 0,
|
||||
checksFailed: apiDto.checksFailed || 0,
|
||||
totalChecks: (apiDto.checksPassed || 0) + (apiDto.checksFailed || 0),
|
||||
successRate: HealthMetricDisplay.formatSuccessRate(apiDto.checksPassed, apiDto.checksFailed),
|
||||
successRate: HealthMetricFormatter.formatSuccessRate(apiDto.checksPassed, apiDto.checksFailed),
|
||||
};
|
||||
|
||||
// Build components
|
||||
const components: HealthComponent[] = (apiDto.components || []).map((component) => ({
|
||||
name: component.name,
|
||||
status: component.status,
|
||||
statusLabel: HealthComponentDisplay.formatStatusLabel(component.status),
|
||||
statusColor: HealthComponentDisplay.formatStatusColor(component.status),
|
||||
statusIcon: HealthComponentDisplay.formatStatusIcon(component.status),
|
||||
statusLabel: HealthComponentFormatter.formatStatusLabel(component.status),
|
||||
statusColor: HealthComponentFormatter.formatStatusColor(component.status),
|
||||
statusIcon: HealthComponentFormatter.formatStatusIcon(component.status),
|
||||
lastCheck: component.lastCheck || lastUpdated,
|
||||
formattedLastCheck: HealthComponentDisplay.formatTimestamp(component.lastCheck || lastUpdated),
|
||||
responseTime: HealthMetricDisplay.formatResponseTime(component.responseTime),
|
||||
errorRate: HealthMetricDisplay.formatErrorRate(component.errorRate),
|
||||
formattedLastCheck: HealthComponentFormatter.formatTimestamp(component.lastCheck || lastUpdated),
|
||||
responseTime: HealthMetricFormatter.formatResponseTime(component.responseTime),
|
||||
errorRate: HealthMetricFormatter.formatErrorRate(component.errorRate),
|
||||
}));
|
||||
|
||||
// Build alerts
|
||||
@@ -57,10 +57,10 @@ export class HealthViewDataBuilder {
|
||||
title: alert.title,
|
||||
message: alert.message,
|
||||
timestamp: alert.timestamp,
|
||||
formattedTimestamp: HealthAlertDisplay.formatTimestamp(alert.timestamp),
|
||||
relativeTime: HealthAlertDisplay.formatRelativeTime(alert.timestamp),
|
||||
severity: HealthAlertDisplay.formatSeverity(alert.type),
|
||||
severityColor: HealthAlertDisplay.formatSeverityColor(alert.type),
|
||||
formattedTimestamp: HealthAlertFormatter.formatTimestamp(alert.timestamp),
|
||||
relativeTime: HealthAlertFormatter.formatRelativeTime(alert.timestamp),
|
||||
severity: HealthAlertFormatter.formatSeverity(alert.type),
|
||||
severityColor: HealthAlertFormatter.formatSeverityColor(alert.type),
|
||||
}));
|
||||
|
||||
// Calculate derived fields
|
||||
@@ -77,7 +77,7 @@ export class HealthViewDataBuilder {
|
||||
hasDegradedComponents,
|
||||
hasErrorComponents,
|
||||
lastUpdated,
|
||||
formattedLastUpdated: HealthStatusDisplay.formatTimestamp(lastUpdated),
|
||||
formattedLastUpdated: HealthStatusFormatter.formatTimestamp(lastUpdated),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user