feat: include agent ratings in user profile and resolve field option labels in agent service transformations
This commit is contained in:
@@ -1075,6 +1075,7 @@ export class AgentsService {
|
|||||||
slug: true,
|
slug: true,
|
||||||
name: true,
|
name: true,
|
||||||
fieldType: true,
|
fieldType: true,
|
||||||
|
options: true,
|
||||||
section: {
|
section: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
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
|
// Transform to a more usable format
|
||||||
const transformedValues = fieldValues.map((fv) => ({
|
const transformedValues = fieldValues.map((fv) => {
|
||||||
fieldSlug: fv.field.slug,
|
const rawValue = this.extractValue(fv);
|
||||||
fieldName: fv.field.name,
|
const labelValue = resolveLabel(rawValue, fv.field.options);
|
||||||
fieldType: fv.field.fieldType,
|
return {
|
||||||
sectionSlug: fv.field.section.slug,
|
fieldSlug: fv.field.slug,
|
||||||
sectionName: fv.field.section.name,
|
fieldName: fv.field.name,
|
||||||
value: this.extractValue(fv),
|
fieldType: fv.field.fieldType,
|
||||||
}));
|
sectionSlug: fv.field.section.slug,
|
||||||
|
sectionName: fv.field.section.name,
|
||||||
|
value: labelValue,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
agentProfileId: profile.id,
|
agentProfileId: profile.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user