fix
This commit is contained in:
@@ -298,8 +298,16 @@ export class ProfileFieldsService {
|
||||
// Map normalized names to their primary slug for de-duplication
|
||||
const nameToSlugMap = new Map<string, string>();
|
||||
|
||||
// Options to exclude from search filters (still available on profile forms via admin)
|
||||
const EXCLUDED_OPTION_VALUES = new Set(['prefer_not_to_say', 'prefer-not-to-say', 'preferNotToSay']);
|
||||
const isExcludedOption = (opt: { label: string; value: string }) => {
|
||||
if (EXCLUDED_OPTION_VALUES.has(opt.value)) return true;
|
||||
return opt.label.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '') === 'prefer_not_to_say';
|
||||
};
|
||||
|
||||
for (const field of fields) {
|
||||
const fieldOptions = (field.options as { label: string; value: string }[]) || [];
|
||||
const rawOptions = (field.options as { label: string; value: string }[]) || [];
|
||||
const fieldOptions = rawOptions.filter((opt) => !isExcludedOption(opt));
|
||||
const normalizedName = field.name.toLowerCase().trim();
|
||||
|
||||
// Check if we already have a field with this name (different slug, same name)
|
||||
@@ -341,6 +349,61 @@ export class ProfileFieldsService {
|
||||
}
|
||||
}
|
||||
|
||||
// Append TAG_INPUT expertise_areas as a dynamic filter — options aggregated from agent-entered values
|
||||
const expertiseField = await this.prisma.profileField.findFirst({
|
||||
where: {
|
||||
slug: 'expertise_areas',
|
||||
isActive: true,
|
||||
fieldType: FieldType.TAG_INPUT,
|
||||
section: {
|
||||
isActive: true,
|
||||
OR: [
|
||||
{ isGlobal: true },
|
||||
{ agentTypeSections: { some: {} } },
|
||||
],
|
||||
},
|
||||
},
|
||||
select: { id: true, name: true, slug: true, fieldType: true },
|
||||
});
|
||||
|
||||
if (expertiseField && !mergedFields.has(expertiseField.slug)) {
|
||||
const fieldValues = await this.prisma.profileFieldValue.findMany({
|
||||
where: {
|
||||
fieldId: expertiseField.id,
|
||||
jsonValue: { not: Prisma.JsonNull },
|
||||
},
|
||||
select: { jsonValue: true },
|
||||
});
|
||||
|
||||
// value → label (preserve first-seen label casing)
|
||||
const areaMap = new Map<string, string>();
|
||||
for (const fv of fieldValues) {
|
||||
const arr = fv.jsonValue as unknown;
|
||||
if (!Array.isArray(arr)) continue;
|
||||
for (const item of arr) {
|
||||
if (typeof item !== 'string') continue;
|
||||
// Strip " - N yrs" / " – N years" suffix used in the profile UI
|
||||
const areaName = item.replace(/\s*[-–]\s*\d+\s*(yrs?|years?)\s*$/i, '').trim();
|
||||
if (!areaName) continue;
|
||||
const value = areaName.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '');
|
||||
if (!value) continue;
|
||||
if (!areaMap.has(value)) areaMap.set(value, areaName);
|
||||
}
|
||||
}
|
||||
|
||||
if (areaMap.size > 0) {
|
||||
const options = Array.from(areaMap.entries())
|
||||
.map(([value, label]) => ({ label, value }))
|
||||
.sort((a, b) => a.label.localeCompare(b.label));
|
||||
mergedFields.set(expertiseField.slug, {
|
||||
slug: expertiseField.slug,
|
||||
name: expertiseField.name,
|
||||
fieldType: expertiseField.fieldType,
|
||||
options,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(mergedFields.values());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user