add validate rules
This commit is contained in:
@@ -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' })
|
||||
|
||||
Reference in New Issue
Block a user