Skip to content

Commit 00ec6e2

Browse files
authored
Merge pull request #81 from topcoder-platform/PM-3497_talent-search
PM-3497 - fix user country & wins
2 parents f9f1281 + 3f22e0b commit 00ec6e2

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import { Body, Controller, HttpCode, HttpStatus, Post, UseGuards } from "@nestjs/common";
2-
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
1+
import {
2+
Body,
3+
Controller,
4+
HttpCode,
5+
HttpStatus,
6+
Post,
7+
UseGuards,
8+
} from "@nestjs/common";
9+
import {
10+
ApiBearerAuth,
11+
ApiOperation,
12+
ApiResponse,
13+
ApiTags,
14+
} from "@nestjs/swagger";
315
import { MemberSearchBodyDto } from "./dto/member-search.dto";
416
import { MemberSearchResponseDto } from "./dto/member-search-response.dto";
517
import { MemberSearchService } from "./member-search.service";

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ describe("MemberSearchService", () => {
5656

5757
expect(dataSql).toContain("WITH recently_active AS");
5858
expect(dataSql).not.toContain("requested_skills AS");
59-
expect(dataSql).toContain('ORDER BY "matchIndex" DESC NULLS LAST, m.handle ASC');
59+
expect(dataSql).toContain(
60+
'ORDER BY "matchIndex" DESC NULLS LAST, m.handle ASC',
61+
);
6062

6163
expect(countSql).toContain("SELECT COUNT(*)::integer AS total");
6264

@@ -85,7 +87,9 @@ describe("MemberSearchService", () => {
8587
});
8688

8789
it("uses filter params for count query but excludes pagination params", async () => {
88-
mockDbService.query.mockResolvedValueOnce([]).mockResolvedValueOnce([{ total: 0 }]);
90+
mockDbService.query
91+
.mockResolvedValueOnce([])
92+
.mockResolvedValueOnce([{ total: 0 }]);
8993

9094
await service.search({
9195
country: "us",
@@ -99,7 +103,9 @@ describe("MemberSearchService", () => {
99103
const dataParams = mockDbService.query.mock.calls[0][1] as unknown[];
100104
const countParams = mockDbService.query.mock.calls[1][1] as unknown[];
101105

102-
expect(dataSql).toContain('ORDER BY m.handle ASC, "matchIndex" DESC NULLS LAST');
106+
expect(dataSql).toContain(
107+
'ORDER BY m.handle ASC, "matchIndex" DESC NULLS LAST',
108+
);
103109
expect(dataParams).toEqual(["us", 5, 5]);
104110
expect(countParams).toEqual(["us"]);
105111
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ skill_event_stats AS (
8181
SELECT
8282
se.user_id,
8383
se.skill_id,
84-
COUNT(*) FILTER (WHERE LOWER(set_t.name) = 'challenge_win') AS wins,
84+
COUNT(*) FILTER (WHERE LOWER(set_t.name) IN ('challenge_win', 'challenge_2nd_place', 'challenge_3rd_place')) AS wins,
8585
COUNT(*) AS submitted
8686
FROM skills.skill_event se
8787
JOIN skills.skill_event_type set_t ON set_t.id = se.skill_event_type_id
@@ -182,17 +182,17 @@ member_address AS (
182182
// ------------------------------------------------- dynamic WHERE
183183
const where: string[] = [`m.status = 'ACTIVE'`];
184184

185-
if (openToWork === true) {
185+
if (typeof openToWork === "boolean") {
186186
where.push(`m."availableForGigs" = true`);
187187
}
188188

189-
if (recentlyActive === true) {
189+
if (typeof recentlyActive === "boolean") {
190190
where.push(
191191
`EXISTS (SELECT 1 FROM recently_active ra WHERE ra.user_id = m."userId")`,
192192
);
193193
}
194194

195-
if (verifiedProfile === true) {
195+
if (typeof verifiedProfile === "boolean") {
196196
where.push(
197197
`(COALESCE(m.verified, false) = true OR EXISTS (SELECT 1 FROM verified_via_trolley vt WHERE vt.user_id = m."userId"))`,
198198
);
@@ -235,7 +235,7 @@ SELECT
235235
COALESCE(m."availableForGigs", false) AS "openToWork",
236236
TRIM(
237237
COALESCE(maddr.city || ' ', '') ||
238-
COALESCE(m.country, COALESCE(m."competitionCountryCode", COALESCE(m."homeCountryCode", '')))
238+
COALESCE(m."homeCountryCode", COALESCE(m.country, COALESCE(m."competitionCountryCode", '')))
239239
) AS location,
240240
${matchedSkillsExpr} AS "matchedSkills",
241241
${matchIndexExpr} AS "matchIndex"

0 commit comments

Comments
 (0)