feat: include field options and resolve display labels for structured field values in agent service
This commit is contained in:
@@ -1031,6 +1031,7 @@ export class AgentsService {
|
||||
slug: true,
|
||||
name: true,
|
||||
fieldType: true,
|
||||
options: true,
|
||||
section: {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -1043,15 +1044,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) => ({
|
||||
const transformedValues = fieldValues.map((fv) => {
|
||||
const rawValue = this.extractValue(fv);
|
||||
return {
|
||||
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),
|
||||
}));
|
||||
value: rawValue,
|
||||
valueLabel: resolveLabel(rawValue, fv.field.options),
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
agentProfileId: profile.id,
|
||||
|
||||
Reference in New Issue
Block a user