games_app/backend/src/controllers/analyticsController.ts
2026-06-29 15:01:23 +02:00

19 lines
934 B
TypeScript

import { Response } from 'express';
import { AuthRequest } from '../middleware/auth';
import * as analyticsService from '../services/analyticsService';
/** Returns full admin dashboard analytics for the selected filters. */
export async function getDashboardAnalytics(req: AuthRequest, res: Response): Promise<void> {
try {
const preset = typeof req.query.preset === 'string' ? req.query.preset : undefined;
const from = typeof req.query.from === 'string' ? req.query.from : undefined;
const to = typeof req.query.to === 'string' ? req.query.to : undefined;
const gameKey = typeof req.query.gameKey === 'string' ? req.query.gameKey : undefined;
const data = await analyticsService.getAdminDashboardAnalytics({ preset, from, to, gameKey });
res.json(data);
} catch (e) {
const msg = e instanceof Error ? e.message : 'Failed to load dashboard analytics';
res.status(400).json({ error: msg });
}
}