Files
gridpilot.gg/apps/website/lib/services/analytics/DashboardService.ts
2025-12-17 22:17:02 +01:00

50 lines
1.6 KiB
TypeScript

import { AnalyticsApiClient } from '../../api/analytics/AnalyticsApiClient';
import { AnalyticsDashboardPresenter } from '../../presenters/AnalyticsDashboardPresenter';
import { AnalyticsMetricsPresenter } from '../../presenters/AnalyticsMetricsPresenter';
import type { AnalyticsDashboardViewModel, AnalyticsMetricsViewModel } from '../../view-models';
/**
* Dashboard Service
*
* Orchestrates dashboard operations by coordinating API calls and presentation logic.
* All dependencies are injected via constructor.
*/
export class DashboardService {
constructor(
private readonly apiClient: AnalyticsApiClient,
private readonly analyticsDashboardPresenter: AnalyticsDashboardPresenter,
private readonly analyticsMetricsPresenter: AnalyticsMetricsPresenter
) {}
/**
* Get dashboard data with presentation transformation
*/
async getDashboardData(): Promise<AnalyticsDashboardViewModel> {
try {
const dto = await this.apiClient.getDashboardData();
return this.analyticsDashboardPresenter.present(dto);
} catch (error) {
throw error;
}
}
/**
* Get analytics metrics with presentation transformation
*/
async getAnalyticsMetrics(): Promise<AnalyticsMetricsViewModel> {
try {
const dto = await this.apiClient.getAnalyticsMetrics();
return this.analyticsMetricsPresenter.present(dto);
} catch (error) {
throw error;
}
}
/**
* Get dashboard overview (legacy method for backward compatibility)
* TODO: Remove when no longer needed
*/
async getDashboardOverview(): Promise<AnalyticsDashboardViewModel> {
return this.getDashboardData();
}
}