Skip to content

Commit 7ed909f

Browse files
authored
Merge pull request #105 from topcoder-platform/PM-5073_talent-search
PM-5073 - Allow search by preferred roles, remove restriction about skills
2 parents b4970e8 + f2c33cf commit 7ed909f

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

src/reports/member/dto/member-search.dto.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ export class MemberSearchBodyDto {
8383
@IsBoolean()
8484
profileComplete?: boolean;
8585

86+
@ApiPropertyOptional({
87+
description:
88+
"Filter by multiple preferred role values from the member's open-to-work personalization trait.",
89+
type: [String],
90+
example: ["AI_ML_ENGINEER", "FULL_STACK_DEVELOPER"],
91+
})
92+
@IsOptional()
93+
@IsArray()
94+
@IsString({ each: true })
95+
preferredRoles?: string[];
96+
8697
@ApiPropertyOptional({
8798
description:
8899
"Filter by multiple country names or country codes (case-insensitive).",

src/reports/member/member-search.service.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ ORDER BY
422422
verifiedProfile,
423423
profileComplete,
424424
countries,
425+
preferredRoles,
425426
sortBy = "matchIndex",
426427
sortOrder = "desc",
427428
page = 1,
@@ -593,6 +594,14 @@ member_address AS (
593594
]
594595
: [];
595596

597+
const normalizedPreferredRoles = Array.isArray(preferredRoles)
598+
? [
599+
...new Set(
600+
preferredRoles.map((value) => String(value).trim()).filter(Boolean),
601+
),
602+
]
603+
: [];
604+
596605
if (normalizedCountries.length > 0) {
597606
const pCountries = p(normalizedCountries);
598607
where.push(
@@ -604,6 +613,30 @@ member_address AS (
604613
);
605614
}
606615

616+
if (normalizedPreferredRoles.length > 0) {
617+
const pPreferredRoles = p(
618+
normalizedPreferredRoles.map((value) => value.toUpperCase()),
619+
);
620+
where.push(
621+
`EXISTS (
622+
SELECT 1
623+
FROM members."memberTraits" mtpr
624+
INNER JOIN members."memberTraitPersonalization" mtpp
625+
ON mtpp."memberTraitId" = mtpr.id
626+
WHERE mtpr."userId" = m."userId"
627+
AND mtpp.key = 'openToWork'
628+
AND mtpp.value IS NOT NULL
629+
AND mtpp.value::jsonb ? 'preferredRoles'
630+
AND jsonb_typeof(mtpp.value::jsonb -> 'preferredRoles') = 'array'
631+
AND EXISTS (
632+
SELECT 1
633+
FROM jsonb_array_elements_text(mtpp.value::jsonb -> 'preferredRoles') pr
634+
WHERE UPPER(pr) = ANY(${pPreferredRoles}::text[])
635+
)
636+
)`,
637+
);
638+
}
639+
607640
const whereClause = where.join(" AND ");
608641
const skillJoin =
609642
deduped.length > 0
@@ -684,10 +717,20 @@ member_address AS (
684717
// ---------------------------------------------------------------- queries
685718
const ctesBlock = ctes.join(",\n");
686719
const direction = sortOrder === "asc" ? "ASC" : "DESC";
687-
const orderByClause =
688-
sortBy === "handle"
689-
? `m.handle ${direction}, "matchIndex" DESC NULLS LAST`
690-
: `"matchIndex" ${direction} NULLS LAST, m.handle ASC`;
720+
const fallbackPreferredRoleOrder =
721+
deduped.length === 0 && normalizedPreferredRoles.length > 0;
722+
let orderByClause = "";
723+
724+
if (sortBy === "handle") {
725+
orderByClause = `m.handle ${direction}, "matchIndex" DESC NULLS LAST`;
726+
} else if (fallbackPreferredRoleOrder) {
727+
orderByClause =
728+
`EXISTS (SELECT 1 FROM recently_active ra WHERE ra.user_id = m."userId") DESC, ` +
729+
`COALESCE(m."availableForGigs", false) DESC, m.handle ASC`;
730+
} else {
731+
orderByClause = `"matchIndex" ${direction} NULLS LAST, m.handle ASC`;
732+
}
733+
691734
const profileCompleteJoin =
692735
profileComplete === true
693736
? `INNER JOIN profile_complete_filtered pcf ON pcf.user_id = m."userId"`
@@ -712,7 +755,7 @@ SELECT
712755
FROM members.member m
713756
INNER JOIN filtered_members fm ON fm.user_id = m."userId"
714757
${profileCompleteJoin}
715-
LEFT JOIN user_match_data umd ON umd.user_id = m."userId"
758+
${deduped.length > 0 ? 'LEFT JOIN user_match_data umd ON umd.user_id = m."userId"' : ""}
716759
LEFT JOIN verified_via_trolley vt ON vt.user_id = m."userId"
717760
LEFT JOIN member_address maddr ON maddr."userId" = m."userId"
718761
ORDER BY ${orderByClause}

0 commit comments

Comments
 (0)