This commit is contained in:
pradeepkumar
2026-01-24 23:10:05 +05:30
parent 9c7e21e1ad
commit f031113781
4 changed files with 161 additions and 19 deletions

View File

@@ -80,14 +80,15 @@ export class AgentsController {
return this.agentsService.getProfile(userId);
}
// 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' })
async getAgentById(@Param('id', ParseUUIDPipe) id: string) {
return this.agentsService.getProfileById(id);
@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);
}
@Post('profile')
@@ -132,15 +133,23 @@ export class AgentsController {
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' })
// Public parameterized routes - MUST come after specific routes like profile/*
@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' })
async getAgentById(@Param('id', ParseUUIDPipe) id: string) {
return this.agentsService.getProfileById(id);
}
@Get(':id/field-values')
@Public()
@ApiOperation({ summary: 'Get field values for an agent profile by ID (public)' })
@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);
@ApiResponse({ status: 404, description: 'Agent profile not found' })
async getFieldValuesByAgentId(@Param('id', ParseUUIDPipe) id: string) {
return this.agentsService.getFieldValuesByAgentId(id);
}
// Admin endpoints

View File

@@ -498,6 +498,54 @@ export class AgentsService {
};
}
async getFieldValuesByAgentId(agentId: string) {
// Get agent profile by ID
const profile = await this.prisma.agentProfile.findUnique({
where: { id: agentId },
});
if (!profile) {
throw new NotFoundException('Agent profile not found');
}
// Get all field values for this profile
const fieldValues = await this.prisma.agentProfileFieldValue.findMany({
where: { agentProfileId: profile.id },
include: {
field: {
select: {
id: true,
slug: true,
name: true,
fieldType: true,
section: {
select: {
id: true,
slug: true,
name: true,
},
},
},
},
},
});
// Transform to a more usable format
const transformedValues = fieldValues.map((fv) => ({
fieldSlug: fv.field.slug,
fieldName: fv.field.name,
fieldType: fv.field.fieldType,
sectionSlug: fv.field.section.slug,
sectionName: fv.field.section.name,
value: this.extractValue(fv),
}));
return {
agentProfileId: profile.id,
fieldValues: transformedValues,
};
}
private getValueData(
fieldType: string,
value: string | number | boolean | string[] | Record<string, unknown> | null,