Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/reports/member/member-search.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { Body, Controller, HttpCode, HttpStatus, Post, UseGuards } from "@nestjs/common";
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
import {
Body,
Controller,
HttpCode,
HttpStatus,
Post,
UseGuards,
} from "@nestjs/common";
import {
ApiBearerAuth,
ApiOperation,
ApiResponse,
ApiTags,
} from "@nestjs/swagger";
import { MemberSearchBodyDto } from "./dto/member-search.dto";
import { MemberSearchResponseDto } from "./dto/member-search-response.dto";
import { MemberSearchService } from "./member-search.service";
Expand Down
12 changes: 9 additions & 3 deletions src/reports/member/member-search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ describe("MemberSearchService", () => {

expect(dataSql).toContain("WITH recently_active AS");
expect(dataSql).not.toContain("requested_skills AS");
expect(dataSql).toContain('ORDER BY "matchIndex" DESC NULLS LAST, m.handle ASC');
expect(dataSql).toContain(
'ORDER BY "matchIndex" DESC NULLS LAST, m.handle ASC',
);

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

Expand Down Expand Up @@ -85,7 +87,9 @@ describe("MemberSearchService", () => {
});

it("uses filter params for count query but excludes pagination params", async () => {
mockDbService.query.mockResolvedValueOnce([]).mockResolvedValueOnce([{ total: 0 }]);
mockDbService.query
.mockResolvedValueOnce([])
.mockResolvedValueOnce([{ total: 0 }]);

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

expect(dataSql).toContain('ORDER BY m.handle ASC, "matchIndex" DESC NULLS LAST');
expect(dataSql).toContain(
'ORDER BY m.handle ASC, "matchIndex" DESC NULLS LAST',
);
expect(dataParams).toEqual(["us", 5, 5]);
expect(countParams).toEqual(["us"]);
});
Expand Down
10 changes: 5 additions & 5 deletions src/reports/member/member-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ skill_event_stats AS (
SELECT
se.user_id,
se.skill_id,
COUNT(*) FILTER (WHERE LOWER(set_t.name) = 'challenge_win') AS wins,
COUNT(*) FILTER (WHERE LOWER(set_t.name) IN ('challenge_win', 'challenge_2nd_place', 'challenge_3rd_place')) AS wins,
COUNT(*) AS submitted
FROM skills.skill_event se
JOIN skills.skill_event_type set_t ON set_t.id = se.skill_event_type_id
Expand Down Expand Up @@ -182,17 +182,17 @@ member_address AS (
// ------------------------------------------------- dynamic WHERE
const where: string[] = [`m.status = 'ACTIVE'`];

if (openToWork === true) {
if (typeof openToWork === "boolean") {
where.push(`m."availableForGigs" = true`);
}

if (recentlyActive === true) {
if (typeof recentlyActive === "boolean") {
where.push(
`EXISTS (SELECT 1 FROM recently_active ra WHERE ra.user_id = m."userId")`,
);
}

if (verifiedProfile === true) {
if (typeof verifiedProfile === "boolean") {
where.push(
`(COALESCE(m.verified, false) = true OR EXISTS (SELECT 1 FROM verified_via_trolley vt WHERE vt.user_id = m."userId"))`,
);
Expand Down Expand Up @@ -235,7 +235,7 @@ SELECT
COALESCE(m."availableForGigs", false) AS "openToWork",
TRIM(
COALESCE(maddr.city || ' ', '') ||
COALESCE(m.country, COALESCE(m."competitionCountryCode", COALESCE(m."homeCountryCode", '')))
COALESCE(m."homeCountryCode", COALESCE(m.country, COALESCE(m."competitionCountryCode", '')))
) AS location,
${matchedSkillsExpr} AS "matchedSkills",
${matchIndexExpr} AS "matchIndex"
Expand Down
Loading