add validate rules
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
|||||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||||
import { RolesGuard } from '../auth/guards/roles.guard';
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
||||||
import { Roles } from '../auth/decorators/roles.decorator';
|
import { Roles } from '../auth/decorators/roles.decorator';
|
||||||
|
import { Public } from '../auth/decorators/public.decorator';
|
||||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||||
import { UserRole } from '@prisma/client';
|
import { UserRole } from '@prisma/client';
|
||||||
|
|
||||||
@@ -33,9 +34,10 @@ import { UserRole } from '@prisma/client';
|
|||||||
export class AgentsController {
|
export class AgentsController {
|
||||||
constructor(private readonly agentsService: AgentsService) {}
|
constructor(private readonly agentsService: AgentsService) {}
|
||||||
|
|
||||||
// Public endpoints
|
// Public endpoints - accessible by anyone
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@Public()
|
||||||
@ApiOperation({ summary: 'Search and list agents' })
|
@ApiOperation({ summary: 'Search and list agents' })
|
||||||
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
|
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
|
||||||
async searchAgents(@Query() dto: SearchAgentsDto) {
|
async searchAgents(@Query() dto: SearchAgentsDto) {
|
||||||
@@ -43,6 +45,7 @@ export class AgentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('featured')
|
@Get('featured')
|
||||||
|
@Public()
|
||||||
@ApiOperation({ summary: 'Get featured agents' })
|
@ApiOperation({ summary: 'Get featured agents' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -53,6 +56,7 @@ export class AgentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('top-rated')
|
@Get('top-rated')
|
||||||
|
@Public()
|
||||||
@ApiOperation({ summary: 'Get top rated agents' })
|
@ApiOperation({ summary: 'Get top rated agents' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -62,10 +66,11 @@ export class AgentsController {
|
|||||||
return this.agentsService.getTopRatedAgents(limit || 10);
|
return this.agentsService.getTopRatedAgents(limit || 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticated endpoints - must come before :id route
|
// Agent-only endpoints - requires AGENT role
|
||||||
|
|
||||||
@Get('profile/me')
|
@Get('profile/me')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Get current user agent profile' })
|
@ApiOperation({ summary: 'Get current user agent profile' })
|
||||||
@ApiResponse({ status: 200, description: 'Profile retrieved successfully' })
|
@ApiResponse({ status: 200, description: 'Profile retrieved successfully' })
|
||||||
@@ -74,8 +79,9 @@ export class AgentsController {
|
|||||||
return this.agentsService.getProfile(userId);
|
return this.agentsService.getProfile(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameterized route - must come after specific routes
|
// Public parameterized route - must come after specific routes
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@Public()
|
||||||
@ApiOperation({ summary: 'Get agent profile by ID' })
|
@ApiOperation({ summary: 'Get agent profile by ID' })
|
||||||
@ApiResponse({ status: 200, description: 'Agent profile retrieved successfully' })
|
@ApiResponse({ status: 200, description: 'Agent profile retrieved successfully' })
|
||||||
@ApiResponse({ status: 404, description: 'Agent profile not found' })
|
@ApiResponse({ status: 404, description: 'Agent profile not found' })
|
||||||
@@ -84,7 +90,8 @@ export class AgentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('profile')
|
@Post('profile')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Create agent profile' })
|
@ApiOperation({ summary: 'Create agent profile' })
|
||||||
@ApiResponse({ status: 201, description: 'Profile created successfully' })
|
@ApiResponse({ status: 201, description: 'Profile created successfully' })
|
||||||
@@ -97,7 +104,8 @@ export class AgentsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put('profile')
|
@Put('profile')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Update current user agent profile' })
|
@ApiOperation({ summary: 'Update current user agent profile' })
|
||||||
@ApiResponse({ status: 200, description: 'Profile updated successfully' })
|
@ApiResponse({ status: 200, description: 'Profile updated successfully' })
|
||||||
|
|||||||
@@ -15,10 +15,14 @@ import {
|
|||||||
import { UploadService } from './upload.service';
|
import { UploadService } from './upload.service';
|
||||||
import { PresignedUrlDto, PresignedUrlResponseDto } from './dto';
|
import { PresignedUrlDto, PresignedUrlResponseDto } from './dto';
|
||||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||||
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
||||||
|
import { Roles } from '../auth/decorators/roles.decorator';
|
||||||
|
import { UserRole } from '@prisma/client';
|
||||||
|
|
||||||
@ApiTags('upload')
|
@ApiTags('upload')
|
||||||
@Controller('upload')
|
@Controller('upload')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT, UserRole.ADMIN)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
export class UploadController {
|
export class UploadController {
|
||||||
constructor(private readonly uploadService: UploadService) {}
|
constructor(private readonly uploadService: UploadService) {}
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ import { UserRole } from '@prisma/client';
|
|||||||
export class VerificationController {
|
export class VerificationController {
|
||||||
constructor(private readonly verificationService: VerificationService) {}
|
constructor(private readonly verificationService: VerificationService) {}
|
||||||
|
|
||||||
// Agent endpoints
|
// Agent-only endpoints - requires AGENT role
|
||||||
|
|
||||||
@Post('request')
|
@Post('request')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Submit a verification request' })
|
@ApiOperation({ summary: 'Submit a verification request' })
|
||||||
@ApiResponse({ status: 201, description: 'Request submitted successfully' })
|
@ApiResponse({ status: 201, description: 'Request submitted successfully' })
|
||||||
@@ -50,7 +51,8 @@ export class VerificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('my-requests')
|
@Get('my-requests')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Get my verification requests' })
|
@ApiOperation({ summary: 'Get my verification requests' })
|
||||||
@ApiResponse({ status: 200, description: 'Requests retrieved successfully' })
|
@ApiResponse({ status: 200, description: 'Requests retrieved successfully' })
|
||||||
@@ -59,7 +61,8 @@ export class VerificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('request/:id')
|
@Get('request/:id')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Get verification request by ID' })
|
@ApiOperation({ summary: 'Get verification request by ID' })
|
||||||
@ApiResponse({ status: 200, description: 'Request retrieved successfully' })
|
@ApiResponse({ status: 200, description: 'Request retrieved successfully' })
|
||||||
@@ -73,7 +76,8 @@ export class VerificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete('request/:id')
|
@Delete('request/:id')
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
|
@Roles(UserRole.AGENT)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@ApiOperation({ summary: 'Cancel a pending verification request' })
|
@ApiOperation({ summary: 'Cancel a pending verification request' })
|
||||||
@ApiResponse({ status: 200, description: 'Request cancelled successfully' })
|
@ApiResponse({ status: 200, description: 'Request cancelled successfully' })
|
||||||
|
|||||||
Reference in New Issue
Block a user