Skip to content
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

Release 100424 #302

Merged
merged 5 commits into from
Apr 10, 2024
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
9 changes: 9 additions & 0 deletions src/reference/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,15 @@ paths:
in: query
name: filterByAge
description: Array with min and max
- schema:
type: string
enum:
- onlyAccepted
- onlyCandidates
- all
in: query
name: show
description: Show accepted/candidates or both
'/campaigns/{campaign}/clusters':
parameters:
- name: campaign
Expand Down
81 changes: 39 additions & 42 deletions src/routes/campaigns/campaignId/candidates/_get/CandidateBhLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CandidateBhLevel implements CandidateData {
}

async init() {
const result = await tryber.tables.WpAppqEvdBug.do()
const campaignAndBugsQuery = tryber.tables.WpAppqEvdBug.do()
.join(
"wp_appq_evd_profile",
"wp_appq_evd_bug.wp_user_id",
Expand All @@ -56,12 +56,7 @@ class CandidateBhLevel implements CandidateData {
.whereIn("wp_appq_evd_profile.id", this.candidateIds)
.groupBy("wp_appq_evd_profile.id");

const hasLevelOneCourse = await tryber.tables.WpAppqEvdProfile.do()
.join(
"wp_appq_course_tester_status",
"wp_appq_evd_profile.id",
"wp_appq_course_tester_status.tester_id"
)
const hasLevelOneCourseQuery = tryber.tables.WpAppqCourseTesterStatus.do()
.join(
"wp_appq_course",
"wp_appq_course_tester_status.course_id",
Expand All @@ -70,14 +65,9 @@ class CandidateBhLevel implements CandidateData {
.where("wp_appq_course_tester_status.is_completed", 1)
.where("wp_appq_course.level", this.courses.levelone.level)
.where("wp_appq_course.career", this.courses.levelone.career)
.whereIn("wp_appq_evd_profile.id", this.candidateIds);
.whereIn("wp_appq_course_tester_status.tester_id", this.candidateIds);

const hasLevelTwoCourse = await tryber.tables.WpAppqEvdProfile.do()
.join(
"wp_appq_course_tester_status",
"wp_appq_evd_profile.id",
"wp_appq_course_tester_status.tester_id"
)
const hasLevelTwoCourseQuery = tryber.tables.WpAppqCourseTesterStatus.do()
.join(
"wp_appq_course",
"wp_appq_course_tester_status.course_id",
Expand All @@ -86,42 +76,48 @@ class CandidateBhLevel implements CandidateData {
.where("wp_appq_course_tester_status.is_completed", 1)
.where("wp_appq_course.level", this.courses.leveltwo.level)
.where("wp_appq_course.career", this.courses.leveltwo.career)
.whereIn("wp_appq_evd_profile.id", this.candidateIds);
.whereIn("wp_appq_course_tester_status.tester_id", this.candidateIds);

const criticalBugs = await tryber.tables.WpAppqEvdBug.do()
const bugsBySeverityQuery = tryber.tables.WpAppqEvdBug.do()
.join(
"wp_appq_evd_profile",
"wp_appq_evd_bug.wp_user_id",
"wp_appq_evd_profile.wp_user_id"
)
.select(
tryber.ref("id").withSchema("wp_appq_evd_profile").as("tester_id")
tryber.ref("id").withSchema("wp_appq_evd_profile").as("tester_id"),
"severity_id"
)
.count({ bug: tryber.ref("id").withSchema("wp_appq_evd_bug") })
.where("status_id", 2)
.where("severity_id", 4)
.whereIn("wp_appq_evd_profile.id", this.candidateIds)
.groupBy("wp_appq_evd_bug.wp_user_id");
const highBugs = await tryber.tables.WpAppqEvdBug.do()
.join(
"wp_appq_evd_profile",
"wp_appq_evd_bug.wp_user_id",
"wp_appq_evd_profile.wp_user_id"
)
.select(
tryber.ref("id").withSchema("wp_appq_evd_profile").as("tester_id")
)
.count({ bug: tryber.ref("id").withSchema("wp_appq_evd_bug") })
.where("status_id", 2)
.where("severity_id", 3)
.whereIn("wp_appq_evd_profile.id", this.candidateIds)
.groupBy("wp_appq_evd_bug.wp_user_id");
.whereIn("severity_id", [3, 4])
.whereIn("wp_appq_evd_profile.id", this.candidateIds);

this._candidateData = result.map((candidate) => {
const highBug = highBugs.find((bug) => bug.tester_id === candidate.id);
const criticalBug = criticalBugs.find(
(bug) => bug.tester_id === candidate.id
);
const [
campaignAndBugs,
hasLevelOneCourse,
hasLevelTwoCourse,
bugsBySeverity,
] = await Promise.all([
campaignAndBugsQuery,
hasLevelOneCourseQuery,
hasLevelTwoCourseQuery,
bugsBySeverityQuery,
]);

const criticalBugs = bugsBySeverity
.filter((bug) => bug.severity_id === 4)
.reduce((acc, bug) => {
acc[bug.tester_id] = (acc[bug.tester_id] || 0) + 1;
return acc;
}, {} as Record<number, number>);
const highBugs = bugsBySeverity
.filter((bug) => bug.severity_id === 3)
.reduce((acc, bug) => {
acc[bug.tester_id] = (acc[bug.tester_id] || 0) + 1;
return acc;
}, {} as Record<number, number>);

this._candidateData = campaignAndBugs.map((candidate) => {
return {
id: candidate.id,
campaigns: candidate.campaigns ? Number(candidate.campaigns) : 0,
Expand All @@ -132,8 +128,9 @@ class CandidateBhLevel implements CandidateData {
levelTwoCourse: hasLevelTwoCourse.some(
(course) => course.tester_id === candidate.id
),
highBugs: highBug ? Number(highBug.bug) : 0,
criticalBugs: criticalBug ? Number(criticalBug.bug) : 0,
highBugs: candidate.id in highBugs ? highBugs[candidate.id] : 0,
criticalBugs:
candidate.id in criticalBugs ? criticalBugs[candidate.id] : 0,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CandidateDevices implements CandidateData {
private campaignId: number;
private candidateIds: number[];
private filters?: { os?: string[] };
private show: "onlyAccepted" | "onlyCandidates" | "all" = "all";

private _devices:
| {
Expand All @@ -22,21 +23,25 @@ class CandidateDevices implements CandidateData {
| {
id: number;
devices: string;
selected_device: number;
}[]
| undefined;

constructor({
campaignId,
candidateIds,
filters,
show,
}: {
campaignId: number;
candidateIds: number[];
filters?: { os?: string[] };
show: "onlyAccepted" | "onlyCandidates" | "all";
}) {
this.candidateIds = candidateIds;
this.filters = filters;
this.campaignId = campaignId;
this.show = show;
}

get devices() {
Expand All @@ -49,7 +54,7 @@ class CandidateDevices implements CandidateData {
}

async init() {
const query = tryber.tables.WpCrowdAppqDevice.do()
const deviceQuery = tryber.tables.WpCrowdAppqDevice.do()
.select(
tryber.ref("id").withSchema("wp_crowd_appq_device"),
"manufacturer",
Expand All @@ -71,27 +76,34 @@ class CandidateDevices implements CandidateData {

if (this.filters?.os) {
const operativeSystems = this.filters.os;
query.where((query) => {
deviceQuery.where((query) => {
for (const os of operativeSystems) {
query.orWhereLike("wp_appq_evd_platform.name", `%${os}%`);
}
});
}

this._devices = await query;
this._candidateDevices = await tryber.tables.WpCrowdAppqHasCandidate.do()
const candidateDevicesQuery = tryber.tables.WpCrowdAppqHasCandidate.do()
.join(
"wp_appq_evd_profile",
"wp_crowd_appq_has_candidate.user_id",
"wp_appq_evd_profile.wp_user_id"
)
.select(
tryber.ref("id").withSchema("wp_appq_evd_profile").as("id"),
"devices"
"devices",
"selected_device"
)
.where("campaign_id", this.campaignId)
.whereIn("wp_appq_evd_profile.id", this.candidateIds);

const [devices, candidateDevices] = await Promise.all([
deviceQuery,
candidateDevicesQuery,
]);
this._devices = devices;
this._candidateDevices = candidateDevices;

return;
}

Expand Down Expand Up @@ -131,9 +143,14 @@ class CandidateDevices implements CandidateData {

if (!candidateDevicesIds) return "none";

if (candidateDevicesIds.devices === "0") return "all";
const devices =
this.show === "onlyAccepted"
? candidateDevicesIds.selected_device.toString()
: candidateDevicesIds.devices;

if (devices === "0") return "all";

return candidateDevicesIds.devices.split(",");
return devices.split(",");
}

isCandidateFiltered(candidate: { id: number }) {
Expand Down
21 changes: 18 additions & 3 deletions src/routes/campaigns/campaignId/candidates/_get/Candidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { tryber } from "@src/features/database";

class Candidates {
private campaign_id: number;
constructor({ campaign_id }: { campaign_id: number }) {
private show: "onlyAccepted" | "onlyCandidates" | "all" = "all";
constructor({
campaign_id,
show,
}: {
campaign_id: number;
show: "onlyAccepted" | "onlyCandidates" | "all";
}) {
this.campaign_id = campaign_id;
this.show = show;
}

async get() {
return await tryber.tables.WpCrowdAppqHasCandidate.do()
const query = tryber.tables.WpCrowdAppqHasCandidate.do()
.join(
"wp_appq_evd_profile",
"wp_crowd_appq_has_candidate.user_id",
Expand All @@ -24,10 +32,17 @@ class Candidates {
"surname"
)
.where("campaign_id", this.campaign_id)
.where("accepted", 0)
.where("name", "<>", "Deleted User")
.orderBy("wp_appq_activity_level.level_id", "desc")
.orderBy("wp_appq_evd_profile.id", "desc");

if (this.show === "onlyAccepted") {
query.where("accepted", 1);
} else if (this.show === "onlyCandidates") {
query.where("accepted", 0);
}

return await query;
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/routes/campaigns/campaignId/candidates/_get/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import OpenapiError from "@src/features/OpenapiError";
import { tryber } from "@src/features/database";
import UserRoute from "@src/features/routes/UserRoute";
import { CandidateBhLevel } from "./CandidateBhLevel";
import { CandidateBusinessCampaigns } from "./CandidateBusinessCampaigns";
import { CandidateDevices } from "./CandidateDevices";
import { CandidateLevels } from "./CandidateLevel";
import { CandidateProfile } from "./CandidateProfile";
import { CandidateQuestions } from "./CandidateQuestions";
import { Candidates } from "./Candidates";
import { CandidateBusinessCampaigns } from "./CandidateBusinessCampaigns";

type filterByItem = string | string[];
type filterBy = Record<
Expand All @@ -27,6 +27,8 @@ export default class RouteItem extends UserRoute<{
private limit: number;
private hasLimit: boolean = false;
private fields: { type: "question"; id: number }[] = [];
private show: NonNullable<NonNullable<RouteItem["query"]>["show"]> =
"onlyCandidates";
private filters:
| {
os?: string[];
Expand Down Expand Up @@ -54,6 +56,8 @@ export default class RouteItem extends UserRoute<{
this.hasLimit = true;
}

if (query.show) this.show = query.show;

if (query.fields) {
query.fields.split(",").map((field) => {
const match = field.match(/^question_(\d+)$/);
Expand Down Expand Up @@ -294,12 +298,14 @@ export default class RouteItem extends UserRoute<{
private async getCandidates() {
const candidatesRetriever = new Candidates({
campaign_id: this.campaign_id,
show: this.show,
});
const candidates = await candidatesRetriever.get();

const deviceGetter = new CandidateDevices({
campaignId: this.campaign_id,
candidateIds: candidates.map((candidate) => candidate.id),
show: this.show,
...(this.filters?.os && { filters: { os: this.filters?.os } }),
});
await deviceGetter.init();
Expand Down
Loading
Loading