add validate rules

This commit is contained in:
pradeepkumar
2026-01-11 22:09:50 +05:30
parent c72be7d2ac
commit c04ca2bcef
3 changed files with 28 additions and 12 deletions

View File

@@ -25,6 +25,7 @@ import {
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { Roles } from '../auth/decorators/roles.decorator';
import { Public } from '../auth/decorators/public.decorator';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { UserRole } from '@prisma/client';
@@ -33,9 +34,10 @@ import { UserRole } from '@prisma/client';
export class AgentsController {
constructor(private readonly agentsService: AgentsService) {}
// Public endpoints
// Public endpoints - accessible by anyone
@Get()
@Public()
@ApiOperation({ summary: 'Search and list agents' })
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
async searchAgents(@Query() dto: SearchAgentsDto) {
@@ -43,6 +45,7 @@ export class AgentsController {
}
@Get('featured')
@Public()
@ApiOperation({ summary: 'Get featured agents' })
@ApiResponse({
status: 200,
@@ -53,6 +56,7 @@ export class AgentsController {
}
@Get('top-rated')
@Public()
@ApiOperation({ summary: 'Get top rated agents' })
@ApiResponse({
status: 200,
@@ -62,10 +66,11 @@ export class AgentsController {
return this.agentsService.getTopRatedAgents(limit || 10);
}
// Authenticated endpoints - must come before :id route
// Agent-only endpoints - requires AGENT role
@Get('profile/me')
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.AGENT)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get current user agent profile' })
@ApiResponse({ status: 200, description: 'Profile retrieved successfully' })
@@ -74,8 +79,9 @@ export class AgentsController {
return this.agentsService.getProfile(userId);
}
// Parameterized route - must come after specific routes
// Public parameterized route - must come after specific routes
@Get(':id')
@Public()
@ApiOperation({ summary: 'Get agent profile by ID' })
@ApiResponse({ status: 200, description: 'Agent profile retrieved successfully' })
@ApiResponse({ status: 404, description: 'Agent profile not found' })
@@ -84,7 +90,8 @@ export class AgentsController {
}
@Post('profile')
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.AGENT)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create agent profile' })
@ApiResponse({ status: 201, description: 'Profile created successfully' })
@@ -97,7 +104,8 @@ export class AgentsController {
}
@Put('profile')
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.AGENT)
@ApiBearerAuth()
@ApiOperation({ summary: 'Update current user agent profile' })
@ApiResponse({ status: 200, description: 'Profile updated successfully' })