-
Notifications
You must be signed in to change notification settings - Fork 0
feat(PM-4203): Filter by skills #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |
| WITH member_skills AS ( | ||
| SELECT | ||
| us.user_id, | ||
| COUNT(*) AS skill_count | ||
| COUNT(*) AS skill_count, | ||
| ARRAY_AGG(DISTINCT us.skill_id::uuid) AS skill_ids | ||
| FROM skills.user_skill us | ||
| GROUP BY us.user_id | ||
| HAVING COUNT(*) >= 3 | ||
|
|
@@ -16,6 +17,7 @@ WHERE m.description IS NOT NULL | |
| AND m."photoURL" <> '' | ||
| AND m."homeCountryCode" IS NOT NULL | ||
| AND ($1::text IS NULL OR COALESCE(m."homeCountryCode", m."competitionCountryCode") = $1) | ||
| AND ($3::uuid[] IS NULL OR ms.skill_ids && $3::uuid[]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| AND ( | ||
| $2::boolean IS NULL | ||
| OR m."availableForGigs" = $2::boolean | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,8 @@ | |
| WITH member_skills AS ( | ||
| SELECT | ||
| us.user_id, | ||
| COUNT(*) AS skill_count | ||
| COUNT(*) AS skill_count, | ||
| ARRAY_AGG(DISTINCT us.skill_id::uuid) AS skill_ids | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| FROM skills.user_skill us | ||
| GROUP BY us.user_id | ||
| HAVING COUNT(*) >= 3 -- Filter early to reduce dataset | ||
|
|
@@ -59,6 +60,7 @@ WHERE m.description IS NOT NULL | |
| AND m."photoURL" <> '' | ||
| AND m."homeCountryCode" IS NOT NULL | ||
| AND ($1::text IS NULL OR COALESCE(m."homeCountryCode", m."competitionCountryCode") = $1) | ||
| AND ($5::uuid[] IS NULL OR ms.skill_ids && $5::uuid[]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| AND ( | ||
| $2::boolean IS NULL | ||
| OR m."availableForGigs" = $2::boolean | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,24 @@ export class CompletedProfilesQueryDto { | |
| @IsBoolean() | ||
| openToWork?: boolean; | ||
|
|
||
| @ApiPropertyOptional({ | ||
| name: "skillId", | ||
| description: "Filter by member skill IDs", | ||
| type: String, | ||
| isArray: true, | ||
| example: ["4b0f5f0a-1234-5678-9abc-def012345678"], | ||
| }) | ||
| @IsOptional() | ||
| @Transform(({ value }) => { | ||
| if (value === undefined || value === null) { | ||
| return undefined; | ||
| } | ||
| const values = Array.isArray(value) ? value : [value]; | ||
| return values.map((v) => String(v)).filter((v) => v.trim().length > 0); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💡 |
||
| }) | ||
| @IsString({ each: true }) | ||
| skillId?: string[]; | ||
|
|
||
| @ApiPropertyOptional({ | ||
| description: "Page number (1-based)", | ||
| example: "1", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,15 +266,23 @@ export class TopcoderReportsController { | |
| summary: "List of members with 100% completed profiles", | ||
| }) | ||
| getCompletedProfiles(@Query() query: CompletedProfilesQueryDto) { | ||
| const { countryCode, page, perPage, openToWork } = query; | ||
| const { countryCode, page, perPage, openToWork, skillId } = query; | ||
| const parsedPage = Math.max(Number(page || 1), 1); | ||
| const parsedPerPage = Math.min(Math.max(Number(perPage || 50), 1), 200); | ||
|
|
||
| const rawSkillIds = Array.isArray(skillId) | ||
| ? skillId | ||
| : skillId !== undefined && skillId !== null | ||
| ? [skillId] | ||
| : []; | ||
| const skillIds = rawSkillIds.filter((id) => id && id.trim().length > 0); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
|
|
||
| return this.reports.getCompletedProfiles( | ||
| countryCode, | ||
| parsedPage, | ||
| parsedPerPage, | ||
| openToWork, | ||
| skillIds.length > 0 ? skillIds : undefined, | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -660,13 +660,17 @@ export class TopcoderReportsService { | |
| page = 1, | ||
| perPage = 50, | ||
| openToWork?: boolean, | ||
| skillIds?: string[], | ||
| ) { | ||
| const safePage = Number.isFinite(page) ? Math.max(Math.floor(page), 1) : 1; | ||
| const safePerPage = Number.isFinite(perPage) | ||
| ? Math.min(Math.max(Math.floor(perPage), 1), 200) | ||
| : 50; | ||
| const offset = (safePage - 1) * safePerPage; | ||
|
|
||
| const hasSkillIds = Array.isArray(skillIds) && skillIds.length > 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💡 |
||
| const skillIdsParam = hasSkillIds ? skillIds : null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
|
|
||
| const countQuery = this.sql.load( | ||
| "reports/topcoder/completed-profiles-count.sql", | ||
| ); | ||
|
|
@@ -675,6 +679,7 @@ export class TopcoderReportsService { | |
| [ | ||
| countryCode || null, | ||
| typeof openToWork === "boolean" ? openToWork : null, | ||
| skillIdsParam, | ||
| ], | ||
| ); | ||
| const total = Number(countRows?.[0]?.total ?? 0); | ||
|
|
@@ -685,6 +690,7 @@ export class TopcoderReportsService { | |
| typeof openToWork === "boolean" ? openToWork : null, | ||
| safePerPage, | ||
| offset, | ||
| skillIdsParam, | ||
| ]); | ||
|
|
||
| const data = rows.map((row) => ({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[⚠️
performance]Using
ARRAY_AGG(DISTINCT us.skill_id::uuid)can potentially lead to performance issues if the dataset is large, as it requires sorting to remove duplicates. Consider evaluating the performance impact and whether this aggregation is necessary for the query's purpose.