From 623fb9283f4e6300381f592094a2e81072f8d417 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Wed, 15 Apr 2026 23:54:37 +0530 Subject: [PATCH] feat: add sort order to agent profile field value queries by section and field position --- src/agents/agents.service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/agents/agents.service.ts b/src/agents/agents.service.ts index c6e2bb5..a99729d 100644 --- a/src/agents/agents.service.ts +++ b/src/agents/agents.service.ts @@ -1071,7 +1071,7 @@ export class AgentsService { throw new NotFoundException('Agent profile not found'); } - // Get all field values for this profile + // Get all field values for this profile, ordered by admin-defined section + field sort order const fieldValues = await this.prisma.agentProfileFieldValue.findMany({ where: { agentProfileId: profile.id }, include: { @@ -1092,6 +1092,10 @@ export class AgentsService { }, }, }, + orderBy: [ + { field: { section: { sortOrder: 'asc' } } }, + { field: { sortOrder: 'asc' } }, + ], }); // Helper to resolve a raw value to its option label (for SELECT/RADIO/MULTI_SELECT fields) @@ -1150,7 +1154,7 @@ export class AgentsService { throw new NotFoundException('Agent profile not found'); } - // Get all field values for this profile + // Get all field values for this profile, ordered by admin-defined section + field sort order const fieldValues = await this.prisma.agentProfileFieldValue.findMany({ where: { agentProfileId: profile.id }, include: { @@ -1171,6 +1175,10 @@ export class AgentsService { }, }, }, + orderBy: [ + { field: { section: { sortOrder: 'asc' } } }, + { field: { sortOrder: 'asc' } }, + ], }); // Helper to resolve a raw value to its option label (for SELECT/RADIO/MULTI_SELECT fields)