import { Controller, Get, Param, Query, ParseUUIDPipe, UseGuards, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiQuery } from '@nestjs/swagger'; import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; import { CurrentTenant } from '../../tenants/decorators/current-tenant.decorator'; import { CurrentUser } from '../../auth/decorators/current-user.decorator'; import { CommissionsDashboardService } from '../services/commissions-dashboard.service'; @ApiTags('Commissions - Dashboard') @ApiBearerAuth() @UseGuards(JwtAuthGuard) @Controller('commissions/dashboard') export class DashboardController { constructor(private readonly dashboardService: CommissionsDashboardService) {} @Get('summary') @ApiOperation({ summary: 'Get commissions dashboard summary' }) @ApiResponse({ status: 200, description: 'Dashboard summary' }) async getSummary(@CurrentTenant() tenantId: string) { return this.dashboardService.getSummary(tenantId); } @Get('by-user') @ApiOperation({ summary: 'Get earnings breakdown by user' }) @ApiQuery({ name: 'date_from', required: false, type: String }) @ApiQuery({ name: 'date_to', required: false, type: String }) async getEarningsByUser( @CurrentTenant() tenantId: string, @Query('date_from') dateFrom?: string, @Query('date_to') dateTo?: string, ) { return this.dashboardService.getEarningsByUser( tenantId, dateFrom ? new Date(dateFrom) : undefined, dateTo ? new Date(dateTo) : undefined, ); } @Get('by-period') @ApiOperation({ summary: 'Get earnings breakdown by period' }) async getEarningsByPeriod(@CurrentTenant() tenantId: string) { return this.dashboardService.getEarningsByPeriod(tenantId); } @Get('top-earners') @ApiOperation({ summary: 'Get top earning users' }) @ApiQuery({ name: 'limit', required: false, type: Number, description: 'Number of results (default: 10)' }) @ApiQuery({ name: 'date_from', required: false, type: String }) @ApiQuery({ name: 'date_to', required: false, type: String }) async getTopEarners( @CurrentTenant() tenantId: string, @Query('limit') limit?: number, @Query('date_from') dateFrom?: string, @Query('date_to') dateTo?: string, ) { return this.dashboardService.getTopEarners( tenantId, limit || 10, dateFrom ? new Date(dateFrom) : undefined, dateTo ? new Date(dateTo) : undefined, ); } @Get('my-earnings') @ApiOperation({ summary: 'Get current user earnings' }) @ApiResponse({ status: 200, description: 'User earnings summary' }) async getMyEarnings( @CurrentTenant() tenantId: string, @CurrentUser('id') userId: string, ) { return this.dashboardService.getMyEarnings(tenantId, userId); } @Get('user/:userId/earnings') @ApiOperation({ summary: 'Get specific user earnings' }) @ApiResponse({ status: 200, description: 'User earnings summary' }) async getUserEarnings( @CurrentTenant() tenantId: string, @Param('userId', ParseUUIDPipe) userId: string, ) { return this.dashboardService.getMyEarnings(tenantId, userId); } @Get('scheme/:schemeId/performance') @ApiOperation({ summary: 'Get scheme performance metrics' }) @ApiResponse({ status: 200, description: 'Scheme performance' }) async getSchemePerformance( @CurrentTenant() tenantId: string, @Param('schemeId', ParseUUIDPipe) schemeId: string, ) { return this.dashboardService.getSchemePerformance(tenantId, schemeId); } }