2026-01-11 20:59:12 +05:30
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete,
|
|
|
|
|
Body,
|
|
|
|
|
Param,
|
|
|
|
|
Query,
|
|
|
|
|
UseGuards,
|
|
|
|
|
ParseUUIDPipe,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import {
|
|
|
|
|
ApiTags,
|
|
|
|
|
ApiOperation,
|
|
|
|
|
ApiResponse,
|
|
|
|
|
ApiBearerAuth,
|
|
|
|
|
} from '@nestjs/swagger';
|
|
|
|
|
import { AgentsService } from './agents.service';
|
|
|
|
|
import {
|
|
|
|
|
CreateAgentProfileDto,
|
|
|
|
|
UpdateAgentProfileDto,
|
|
|
|
|
SearchAgentsDto,
|
2026-01-24 21:06:08 +05:30
|
|
|
SaveFieldValuesDto,
|
2026-01-11 20:59:12 +05:30
|
|
|
} from './dto';
|
|
|
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
|
|
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
|
|
|
|
import { Roles } from '../auth/decorators/roles.decorator';
|
2026-01-11 22:09:50 +05:30
|
|
|
import { Public } from '../auth/decorators/public.decorator';
|
2026-01-11 20:59:12 +05:30
|
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
|
|
|
import { UserRole } from '@prisma/client';
|
|
|
|
|
|
|
|
|
|
@ApiTags('agents')
|
|
|
|
|
@Controller('agents')
|
|
|
|
|
export class AgentsController {
|
|
|
|
|
constructor(private readonly agentsService: AgentsService) {}
|
|
|
|
|
|
2026-01-11 22:09:50 +05:30
|
|
|
// Public endpoints - accessible by anyone
|
2026-01-11 20:59:12 +05:30
|
|
|
|
|
|
|
|
@Get()
|
2026-01-11 22:09:50 +05:30
|
|
|
@Public()
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiOperation({ summary: 'Search and list agents' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
|
|
|
|
|
async searchAgents(@Query() dto: SearchAgentsDto) {
|
|
|
|
|
return this.agentsService.searchAgents(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('featured')
|
2026-01-11 22:09:50 +05:30
|
|
|
@Public()
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiOperation({ summary: 'Get featured agents' })
|
|
|
|
|
@ApiResponse({
|
|
|
|
|
status: 200,
|
|
|
|
|
description: 'Featured agents retrieved successfully',
|
|
|
|
|
})
|
|
|
|
|
async getFeaturedAgents(@Query('limit') limit?: number) {
|
|
|
|
|
return this.agentsService.getFeaturedAgents(limit || 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('top-rated')
|
2026-01-11 22:09:50 +05:30
|
|
|
@Public()
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiOperation({ summary: 'Get top rated agents' })
|
|
|
|
|
@ApiResponse({
|
|
|
|
|
status: 200,
|
|
|
|
|
description: 'Top rated agents retrieved successfully',
|
|
|
|
|
})
|
|
|
|
|
async getTopRatedAgents(@Query('limit') limit?: number) {
|
|
|
|
|
return this.agentsService.getTopRatedAgents(limit || 10);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 22:09:50 +05:30
|
|
|
// Agent-only endpoints - requires AGENT role
|
2026-01-11 20:59:12 +05:30
|
|
|
|
|
|
|
|
@Get('profile/me')
|
2026-01-11 22:09:50 +05:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.AGENT)
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Get current user agent profile' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Profile retrieved successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async getMyProfile(@CurrentUser('id') userId: string) {
|
|
|
|
|
return this.agentsService.getProfile(userId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 22:09:50 +05:30
|
|
|
// Public parameterized route - must come after specific routes
|
2026-01-11 20:59:12 +05:30
|
|
|
@Get(':id')
|
2026-01-11 22:09:50 +05:30
|
|
|
@Public()
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiOperation({ summary: 'Get agent profile by ID' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Agent profile retrieved successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Agent profile not found' })
|
|
|
|
|
async getAgentById(@Param('id', ParseUUIDPipe) id: string) {
|
|
|
|
|
return this.agentsService.getProfileById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('profile')
|
2026-01-11 22:09:50 +05:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.AGENT)
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Create agent profile' })
|
|
|
|
|
@ApiResponse({ status: 201, description: 'Profile created successfully' })
|
|
|
|
|
@ApiResponse({ status: 409, description: 'Profile already exists' })
|
|
|
|
|
async createProfile(
|
|
|
|
|
@CurrentUser('id') userId: string,
|
|
|
|
|
@Body() dto: CreateAgentProfileDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.agentsService.createProfile(userId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('profile')
|
2026-01-11 22:09:50 +05:30
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.AGENT)
|
2026-01-11 20:59:12 +05:30
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Update current user agent profile' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Profile updated successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async updateProfile(
|
|
|
|
|
@CurrentUser('id') userId: string,
|
|
|
|
|
@Body() dto: UpdateAgentProfileDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.agentsService.updateProfile(userId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 21:06:08 +05:30
|
|
|
@Put('profile/field-values')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.AGENT)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Save dynamic field values for agent profile' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Field values saved successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async saveFieldValues(
|
|
|
|
|
@CurrentUser('id') userId: string,
|
|
|
|
|
@Body() dto: SaveFieldValuesDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.agentsService.saveFieldValues(userId, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('profile/field-values')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.AGENT)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Get dynamic field values for agent profile' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Field values retrieved successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async getFieldValues(@CurrentUser('id') userId: string) {
|
|
|
|
|
return this.agentsService.getFieldValues(userId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-11 20:59:12 +05:30
|
|
|
// Admin endpoints
|
|
|
|
|
|
|
|
|
|
@Get('admin/list')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Admin: List all agents' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Agents retrieved successfully' })
|
|
|
|
|
async adminListAgents(@Query() dto: SearchAgentsDto) {
|
|
|
|
|
return this.agentsService.getAllAgentsAdmin(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('admin/:id')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Admin: Update agent profile' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Profile updated successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async adminUpdateProfile(
|
|
|
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
|
|
|
@Body() dto: UpdateAgentProfileDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.agentsService.adminUpdateProfile(id, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete('admin/:id')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Admin: Delete agent profile' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Profile deleted successfully' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async adminDeleteProfile(@Param('id', ParseUUIDPipe) id: string) {
|
|
|
|
|
return this.agentsService.adminDeleteProfile(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('admin/:id/verify')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Admin: Verify/unverify agent' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Verification status updated' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async adminVerifyAgent(
|
|
|
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
|
|
|
@Body('isVerified') isVerified: boolean,
|
|
|
|
|
) {
|
|
|
|
|
return this.agentsService.adminVerifyAgent(id, isVerified);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Put('admin/:id/featured')
|
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.ADMIN)
|
|
|
|
|
@ApiBearerAuth()
|
|
|
|
|
@ApiOperation({ summary: 'Admin: Set agent as featured' })
|
|
|
|
|
@ApiResponse({ status: 200, description: 'Featured status updated' })
|
|
|
|
|
@ApiResponse({ status: 404, description: 'Profile not found' })
|
|
|
|
|
async adminSetFeatured(
|
|
|
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
|
|
|
@Body('isFeatured') isFeatured: boolean,
|
|
|
|
|
) {
|
|
|
|
|
return this.agentsService.adminSetFeatured(id, isFeatured);
|
|
|
|
|
}
|
|
|
|
|
}
|