From 87b0c17b441ac7c24d51cc3ff153adf9f61fbc4d Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Wed, 8 Apr 2026 04:11:33 +0530 Subject: [PATCH] feat: include agent ratings in user profile and resolve field option labels in agent service transformations --- src/agents/agents.service.ts | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/agents/agents.service.ts b/src/agents/agents.service.ts index 75f8319..ec1b112 100644 --- a/src/agents/agents.service.ts +++ b/src/agents/agents.service.ts @@ -1075,6 +1075,7 @@ export class AgentsService { slug: true, name: true, fieldType: true, + options: true, section: { select: { id: true, @@ -1087,15 +1088,30 @@ export class AgentsService { }, }); + // Helper to resolve a raw value to its option label (for SELECT/RADIO/MULTI_SELECT fields) + const resolveLabel = (rawValue: any, options: any): any => { + if (!options || !Array.isArray(options) || options.length === 0) return rawValue; + const lookup = (val: any) => { + const match = (options as any[]).find((o: any) => o.value === val || o.value === String(val)); + return match?.label || val; + }; + if (Array.isArray(rawValue)) return rawValue.map(lookup); + return lookup(rawValue); + }; + // 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), - })); + const transformedValues = fieldValues.map((fv) => { + const rawValue = this.extractValue(fv); + const labelValue = resolveLabel(rawValue, fv.field.options); + return { + fieldSlug: fv.field.slug, + fieldName: fv.field.name, + fieldType: fv.field.fieldType, + sectionSlug: fv.field.section.slug, + sectionName: fv.field.section.name, + value: labelValue, + }; + }); return { agentProfileId: profile.id,