Skip to content

Commit 98e56a6

Browse files
committed
Fixed bug where ratings can take in ids that do not exist
1 parent 28d28c2 commit 98e56a6

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/backend/db.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,13 +1404,15 @@ async function UserRatingChallenge(ratingData, jwt) {
14041404

14051405
// iterate the users completions
14061406
for (const data of Object.entries(userProfile.completions)) {
1407-
const [index, { id, time }] = data; // break down the entry
1407+
const [index, { id, time }] = data; // break down the user completion entry
14081408
const challengeProfile = await ChallengeCollection.findOne({ _id: SanitizeAlphaNumeric(id) })
14091409

14101410
if (challengeProfile) {
1411-
// users completions have the challenge id listed as completed
1412-
if (challengeProfile._id.toString() === SanitizeAlphaNumeric(id)) {
1411+
// check if the challengeID given in the request is contained in the users
1412+
// completion data in the database
1413+
if (challengeProfile._id.toString() === challengeID) {
14131414
console.log("[*] User has completed this challenge!")
1415+
console.log(challengeProfile)
14141416
completedChallenge = true;
14151417
break;
14161418
}

0 commit comments

Comments
 (0)