diff --git a/src/features/wp/getUserById/index.ts b/src/features/wp/getUserById/index.ts index 1ab48fb0d..17249ecb1 100644 --- a/src/features/wp/getUserById/index.ts +++ b/src/features/wp/getUserById/index.ts @@ -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"), @@ -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() }; }; diff --git a/src/routes/campaigns/campaignId/candidates/_get/CandidateBhLevel.ts b/src/routes/campaigns/campaignId/candidates/_get/CandidateBhLevel.ts index 4fa01669e..78f9746cd 100644 --- a/src/routes/campaigns/campaignId/candidates/_get/CandidateBhLevel.ts +++ b/src/routes/campaigns/campaignId/candidates/_get/CandidateBhLevel.ts @@ -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( @@ -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, diff --git a/src/routes/campaigns/campaignId/candidates/_get/bhleveldata.spec.ts b/src/routes/campaigns/campaignId/candidates/_get/bhleveldata.spec.ts index 9947c3808..5d6047121 100644 --- a/src/routes/campaigns/campaignId/candidates/_get/bhleveldata.spec.ts +++ b/src/routes/campaigns/campaignId/candidates/_get/bhleveldata.spec.ts @@ -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, }); }; @@ -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, }); }; @@ -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]) { @@ -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]) { @@ -76,6 +83,7 @@ const addAdvancedRequirements = async ({ wp_user_id, campaign_id: Number(i) + 1, severity_id: 4, + profile_id: tester_id, }); } }; @@ -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()]) { @@ -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()]) { @@ -118,6 +128,7 @@ const addVeteranRequirements = async ({ wp_user_id, campaign_id: Number(i) + 1, severity_id: 4, + profile_id: tester_id, }); } }; @@ -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()]) { @@ -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()]) { @@ -160,6 +173,7 @@ const addExpertRequirements = async ({ wp_user_id, campaign_id: Number(i) + 1, severity_id: 4, + profile_id: tester_id, }); } }; @@ -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()]) { @@ -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()]) { @@ -201,6 +217,7 @@ const addChampionRequirements = async ({ wp_user_id, campaign_id: Number(i) + 1, severity_id: 4, + profile_id: tester_id, }); } }; @@ -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 });