Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions apps/backend/src/modules/admin/controllers/analytics.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { Controller, Get, Query, Res, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { Response } from 'express';
import { AuthGuard } from '../../auth/middleware/auth.guard';
import { AdminGuard } from '../../auth/middleware/admin.guard';
import { AnalyticsService } from '../services/analytics.service';
Expand All @@ -11,31 +12,60 @@ import { AnalyticsService } from '../services/analytics.service';
export class AnalyticsController {
constructor(private readonly analyticsService: AnalyticsService) {}

@Get('overview')
@ApiOperation({ summary: 'Get high-level platform analytics overview' })
async getOverview() {
return this.analyticsService.getOverview();
@Get('summary')
@ApiOperation({
summary: 'Get full analytics summary (volume, activity, performance, users, disputes)',
})
async getSummary(@Res({ passthrough: true }) res: Response) {
res.setHeader('Cache-Control', 'public, max-age=300');
return this.analyticsService.getSummary();
}

@Get('volume')
@ApiOperation({ summary: 'Get escrow volume time-series data' })
@ApiQuery({ name: 'period', required: false, enum: ['daily', 'weekly', 'monthly'] })
@ApiQuery({ name: 'from', required: false, type: String })
@ApiQuery({ name: 'to', required: false, type: String })
async getVolume(
@Res({ passthrough: true }) res: Response,
@Query('period') period: 'daily' | 'weekly' | 'monthly' = 'daily',
@Query('from') from?: string,
@Query('to') to?: string,
) {
return this.analyticsService.getVolumeStats(period, from, to);
res.setHeader('Cache-Control', 'public, max-age=900');
const [series, timeSeries] = await Promise.all([
this.analyticsService.getVolumeStats(period, from, to),
this.analyticsService.getVolumeTimeSeries(from, to),
]);
return { series, charts: timeSeries };
}

@Get('users')
@ApiOperation({ summary: 'Get user metrics and weekly active user time-series' })
async getUsers(@Res({ passthrough: true }) res: Response) {
res.setHeader('Cache-Control', 'public, max-age=300');
const [metrics, timeSeries] = await Promise.all([
this.analyticsService.getUserMetrics(),
this.analyticsService.getUserTimeSeries(),
]);
return { metrics, charts: timeSeries };
}

@Get('disputes')
@ApiOperation({ summary: 'Get dispute-related metrics' })
async getDisputes() {
@ApiOperation({ summary: 'Get dispute metrics including resolution and win rates' })
async getDisputes(@Res({ passthrough: true }) res: Response) {
res.setHeader('Cache-Control', 'public, max-age=300');
return this.analyticsService.getDisputeMetrics();
}

@Get('top-users')
@ApiOperation({ summary: 'Get leaderboard of top users by volume' })
async getTopUsers(@Query('limit') limit: string = '10') {
@ApiQuery({ name: 'limit', required: false, type: Number })
async getTopUsers(
@Res({ passthrough: true }) res: Response,
@Query('limit') limit: string = '10',
) {
res.setHeader('Cache-Control', 'public, max-age=300');
return this.analyticsService.getTopUsers(parseInt(limit, 10));
}
}
Loading
Loading