Skip to content

Commit f2c33cf

Browse files
committed
Allow search by preferred roles, remove restriction about skills
1 parent 5cd50ec commit f2c33cf

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
@@ -54,6 +54,7 @@ export class MemberSearchService {
5454
verifiedProfile,
5555
profileComplete,
5656
countries,
57+
preferredRoles,
5758
sortBy = "matchIndex",
5859
sortOrder = "desc",
5960
page = 1,
@@ -225,6 +226,14 @@ member_address AS (
225226
]
226227
: [];
227228

229+
const normalizedPreferredRoles = Array.isArray(preferredRoles)
230+
? [
231+
...new Set(
232+
preferredRoles.map((value) => String(value).trim()).filter(Boolean),
233+
),
234+
]
235+
: [];
236+
228237
if (normalizedCountries.length > 0) {
229238
const pCountries = p(normalizedCountries);
230239
where.push(
@@ -236,6 +245,30 @@ member_address AS (
236245
);
237246
}
238247

248+
if (normalizedPreferredRoles.length > 0) {
249+
const pPreferredRoles = p(
250+
normalizedPreferredRoles.map((value) => value.toUpperCase()),
251+
);
252+
where.push(
253+
`EXISTS (
254+
SELECT 1
255+
FROM members."memberTraits" mtpr
256+
INNER JOIN members."memberTraitPersonalization" mtpp
257+
ON mtpp."memberTraitId" = mtpr.id
258+
WHERE mtpr."userId" = m."userId"
259+
AND mtpp.key = 'openToWork'
260+
AND mtpp.value IS NOT NULL
261+
AND mtpp.value::jsonb ? 'preferredRoles'
262+
AND jsonb_typeof(mtpp.value::jsonb -> 'preferredRoles') = 'array'
263+
AND EXISTS (
264+
SELECT 1
265+
FROM jsonb_array_elements_text(mtpp.value::jsonb -> 'preferredRoles') pr
266+
WHERE UPPER(pr) = ANY(${pPreferredRoles}::text[])
267+
)
268+
)`,
269+
);
270+
}
271+
239272
const whereClause = where.join(" AND ");
240273
const skillJoin =
241274
deduped.length > 0
@@ -316,10 +349,20 @@ member_address AS (
316349
// ---------------------------------------------------------------- queries
317350
const ctesBlock = ctes.join(",\n");
318351
const direction = sortOrder === "asc" ? "ASC" : "DESC";
319-
const orderByClause =
320-
sortBy === "handle"
321-
? `m.handle ${direction}, "matchIndex" DESC NULLS LAST`
322-
: `"matchIndex" ${direction} NULLS LAST, m.handle ASC`;
352+
const fallbackPreferredRoleOrder =
353+
deduped.length === 0 && normalizedPreferredRoles.length > 0;
354+
let orderByClause = "";
355+
356+
if (sortBy === "handle") {
357+
orderByClause = `m.handle ${direction}, "matchIndex" DESC NULLS LAST`;
358+
} else if (fallbackPreferredRoleOrder) {
359+
orderByClause =
360+
`EXISTS (SELECT 1 FROM recently_active ra WHERE ra.user_id = m."userId") DESC, ` +
361+
`COALESCE(m."availableForGigs", false) DESC, m.handle ASC`;
362+
} else {
363+
orderByClause = `"matchIndex" ${direction} NULLS LAST, m.handle ASC`;
364+
}
365+
323366
const profileCompleteJoin =
324367
profileComplete === true
325368
? `INNER JOIN profile_complete_filtered pcf ON pcf.user_id = m."userId"`
@@ -344,7 +387,7 @@ SELECT
344387
FROM members.member m
345388
INNER JOIN filtered_members fm ON fm.user_id = m."userId"
346389
${profileCompleteJoin}
347-
LEFT JOIN user_match_data umd ON umd.user_id = m."userId"
390+
${deduped.length > 0 ? 'LEFT JOIN user_match_data umd ON umd.user_id = m."userId"' : ""}
348391
LEFT JOIN verified_via_trolley vt ON vt.user_id = m."userId"
349392
LEFT JOIN member_address maddr ON maddr."userId" = m."userId"
350393
ORDER BY ${orderByClause}

0 commit comments

Comments
 (0)