- Convert `import type { X }` to `import { type X }` (inline-type-imports style)
- Suppress consistent-type-imports for `typeof import()` in instrument.ts
- Includes uncommitted agent work: metrics module, redis caching, audit logs,
saved searches, circuit breaker, rate limiting, and admin enhancements
Co-Authored-By: Paperclip <noreply@paperclip.ing>
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
|
|
import { type CommandBus, type QueryBus } from '@nestjs/cqrs';
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiOperation,
|
|
ApiParam,
|
|
ApiResponse,
|
|
ApiTags,
|
|
} from '@nestjs/swagger';
|
|
import {
|
|
type JwtPayload,
|
|
CurrentUser,
|
|
JwtAuthGuard,
|
|
RolesGuard,
|
|
Roles,
|
|
} from '@modules/auth';
|
|
import { RecalculateQualityScoreCommand } from '../../application/commands/recalculate-quality-score/recalculate-quality-score.command';
|
|
import { GetAgentDashboardQuery } from '../../application/queries/get-agent-dashboard/get-agent-dashboard.query';
|
|
import { type AgentDashboardData } from '../../domain/repositories/agent.repository';
|
|
|
|
@ApiTags('agents')
|
|
@Controller('agents')
|
|
export class AgentsController {
|
|
constructor(
|
|
private readonly commandBus: CommandBus,
|
|
private readonly queryBus: QueryBus,
|
|
) {}
|
|
|
|
@ApiBearerAuth('JWT')
|
|
@ApiOperation({ summary: 'Get agent dashboard stats' })
|
|
@ApiResponse({ status: 200, description: 'Agent dashboard data' })
|
|
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
@ApiResponse({ status: 403, description: 'Forbidden — only agents' })
|
|
@ApiResponse({ status: 404, description: 'Agent profile not found' })
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('AGENT')
|
|
@Get('me/dashboard')
|
|
async getDashboard(
|
|
@CurrentUser() user: JwtPayload,
|
|
): Promise<AgentDashboardData> {
|
|
return this.queryBus.execute(new GetAgentDashboardQuery(user.sub));
|
|
}
|
|
|
|
@ApiBearerAuth('JWT')
|
|
@ApiOperation({ summary: 'Recalculate quality score (admin/system)' })
|
|
@ApiParam({ name: 'agentId', description: 'Agent ID' })
|
|
@ApiResponse({ status: 201, description: 'Quality score recalculated' })
|
|
@ApiResponse({ status: 401, description: 'Unauthorized' })
|
|
@ApiResponse({ status: 403, description: 'Forbidden — only admins' })
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('ADMIN')
|
|
@Post(':agentId/recalculate-score')
|
|
async recalculateScore(
|
|
@Param('agentId') agentId: string,
|
|
): Promise<{ message: string }> {
|
|
await this.commandBus.execute(
|
|
new RecalculateQualityScoreCommand(agentId),
|
|
);
|
|
return { message: 'Quality score recalculated' };
|
|
}
|
|
}
|