template-saas-backend-v2/src/modules/commissions/controllers/dashboard.controller.ts
Adrian Flores Cortes eb6a83daba feat(sales,commissions): Add Sales and Commissions backend modules
Sales Module (SAAS-018):
- Entities: PipelineStage, Lead, Opportunity, Activity
- Services: LeadsService, OpportunitiesService, ActivitiesService, PipelineService, SalesDashboardService
- Controllers: 25 endpoints for leads, opportunities, activities, pipeline, dashboard
- DTOs: Complete CRUD and query DTOs
- Integration with DDL functions: convert_lead_to_opportunity, update_opportunity_stage, calculate_lead_score

Commissions Module (SAAS-020):
- Entities: CommissionScheme, CommissionAssignment, CommissionPeriod, CommissionEntry
- Services: SchemesService, AssignmentsService, EntriesService, PeriodsService, CommissionsDashboardService
- Controllers: 25 endpoints for schemes, assignments, entries, periods, dashboard
- DTOs: Complete CRUD and query DTOs
- Integration with DDL functions: calculate_commission, close_period, get_user_earnings

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 22:23:02 -06:00

58 lines
1.8 KiB
TypeScript

import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@modules/auth/guards/jwt-auth.guard';
import { CurrentUser } from '@modules/auth/decorators/current-user.decorator';
import { CommissionsDashboardService } from '../services';
import {
CommissionsDashboardDto,
UserEarningsDto,
EntriesByStatusDto,
EntriesBySchemeDto,
EntriesByUserDto,
} from '../dto';
interface RequestUser {
id: string;
tenant_id: string;
email: string;
role: string;
}
@Controller('commissions/dashboard')
@UseGuards(JwtAuthGuard)
export class CommissionsDashboardController {
constructor(private readonly dashboardService: CommissionsDashboardService) {}
@Get()
async getSummary(@CurrentUser() user: RequestUser): Promise<CommissionsDashboardDto> {
return this.dashboardService.getDashboardSummary(user.tenant_id);
}
@Get('my-earnings')
async getMyEarnings(@CurrentUser() user: RequestUser): Promise<UserEarningsDto> {
return this.dashboardService.getUserEarnings(user.tenant_id, user.id);
}
@Get('entries-by-status')
async getEntriesByStatus(@CurrentUser() user: RequestUser): Promise<EntriesByStatusDto[]> {
return this.dashboardService.getEntriesByStatus(user.tenant_id);
}
@Get('entries-by-scheme')
async getEntriesByScheme(@CurrentUser() user: RequestUser): Promise<EntriesBySchemeDto[]> {
return this.dashboardService.getEntriesByScheme(user.tenant_id);
}
@Get('entries-by-user')
async getEntriesByUser(@CurrentUser() user: RequestUser): Promise<EntriesByUserDto[]> {
return this.dashboardService.getEntriesByUser(user.tenant_id);
}
@Get('top-earners')
async getTopEarners(
@CurrentUser() user: RequestUser,
@Query('limit') limit?: number,
): Promise<EntriesByUserDto[]> {
return this.dashboardService.getTopEarners(user.tenant_id, limit || 10);
}
}