Skip to content
Draft
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
6 changes: 3 additions & 3 deletions src/features/wp/getUserById/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tryber } from "@src/features/database";

export default async (userId: number) => {
export default async (wpUserId: number) => {
const results = await tryber.tables.WpAppqEvdProfile.do()
.select(
tryber.ref("id").withSchema("wp_appq_evd_profile").as("testerId"),
Expand All @@ -9,10 +9,10 @@ export default async (userId: number) => {
tryber.ref("user_pass").withSchema("wp_users").as("user_pass")
)
.join("wp_users", "wp_users.ID", "wp_appq_evd_profile.wp_user_id")
.where("wp_users.ID", userId)
.where("wp_users.ID", wpUserId)
.first();

if (!results) return new Error("No user with id " + userId);
if (!results) return new Error("No user with id " + wpUserId);

return { ...results, ID: results.ID.toString() };
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,12 @@ class CandidateBhLevel implements CandidateData {

async init() {
const campaignAndBugsQuery = 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"))
.select(tryber.ref("profile_id").withSchema("wp_appq_evd_bug").as("id"))
.countDistinct({ campaigns: "campaign_id" })
.count({ bug: tryber.ref("id").withSchema("wp_appq_evd_bug") })
.where("status_id", 2)
.whereIn("wp_appq_evd_profile.id", this.candidateIds)
.groupBy("wp_appq_evd_profile.id");
.whereIn("profile_id", this.candidateIds)
.groupBy("profile_id");

const hasLevelOneCourseQuery = tryber.tables.WpAppqCourseTesterStatus.do()
.join(
Expand All @@ -79,18 +74,13 @@ class CandidateBhLevel implements CandidateData {
.whereIn("wp_appq_course_tester_status.tester_id", this.candidateIds);

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"),
"severity_id"
"severity_id",
tryber.ref("profile_id").withSchema("wp_appq_evd_bug").as("tester_id")
)
.where("status_id", 2)
.whereIn("severity_id", [3, 4])
.whereIn("wp_appq_evd_profile.id", this.candidateIds);
.whereIn("profile_id", this.candidateIds);

const [
campaignAndBugs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ const bug = {
};
const addNewbieRequirements = async ({
wp_user_id,
profile_id,
}: {
wp_user_id: number;
profile_id: number;
}) => {
await tryber.tables.WpAppqEvdBug.do().insert({
...bug,
wp_user_id,
campaign_id: 2,
profile_id,
});
};

Expand All @@ -35,11 +38,13 @@ const addRookieRequirements = async ({
...bug,
wp_user_id,
campaign_id: 2,
profile_id: tester_id,
});
await tryber.tables.WpAppqEvdBug.do().insert({
...bug,
wp_user_id,
campaign_id: 2,
profile_id: tester_id,
});
};

Expand All @@ -60,6 +65,7 @@ const addAdvancedRequirements = async ({
...bug,
wp_user_id,
campaign_id: Number(i) + 1,
profile_id: tester_id,
});
}
for (const i in [1, 2]) {
Expand All @@ -68,6 +74,7 @@ const addAdvancedRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 3,
profile_id: tester_id,
});
}
for (const i in [1, 2, 3]) {
Expand All @@ -76,6 +83,7 @@ const addAdvancedRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 4,
profile_id: tester_id,
});
}
};
Expand All @@ -102,6 +110,7 @@ const addVeteranRequirements = async ({
...bug,
wp_user_id,
campaign_id: Number(i) + 1,
profile_id: tester_id,
});
}
for (const i in [...Array(5).keys()]) {
Expand All @@ -110,6 +119,7 @@ const addVeteranRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 3,
profile_id: tester_id,
});
}
for (const i in [...Array(5).keys()]) {
Expand All @@ -118,6 +128,7 @@ const addVeteranRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 4,
profile_id: tester_id,
});
}
};
Expand All @@ -144,6 +155,7 @@ const addExpertRequirements = async ({
...bug,
wp_user_id,
campaign_id: Number(i) + 1,
profile_id: tester_id,
});
}
for (const i in [...Array(15).keys()]) {
Expand All @@ -152,6 +164,7 @@ const addExpertRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 3,
profile_id: tester_id,
});
}
for (const i in [...Array(5).keys()]) {
Expand All @@ -160,6 +173,7 @@ const addExpertRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 4,
profile_id: tester_id,
});
}
};
Expand All @@ -185,6 +199,7 @@ const addChampionRequirements = async ({
...bug,
wp_user_id,
campaign_id: Number(i) + 1,
profile_id: tester_id,
});
}
for (const i in [...Array(40).keys()]) {
Expand All @@ -193,6 +208,7 @@ const addChampionRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 3,
profile_id: tester_id,
});
}
for (const i in [...Array(10).keys()]) {
Expand All @@ -201,6 +217,7 @@ const addChampionRequirements = async ({
wp_user_id,
campaign_id: Number(i) + 1,
severity_id: 4,
profile_id: tester_id,
});
}
};
Expand Down Expand Up @@ -289,7 +306,7 @@ describe("GET /campaigns/:campaignId/candidates - questions ", () => {
},
]);

await addNewbieRequirements({ wp_user_id: 1 });
await addNewbieRequirements({ wp_user_id: 1, profile_id: 1 });
await addRookieRequirements({ tester_id: 2, wp_user_id: 2 });
await addAdvancedRequirements({ tester_id: 3, wp_user_id: 3 });
await addVeteranRequirements({ tester_id: 4, wp_user_id: 4 });
Expand Down
Loading