Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5c27048

Browse files
Fix issue where review summations are not being handled correctly
1 parent 61ddee9 commit 5c27048

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/models/Leaderboard.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ const LeaderboardSchema = new Schema({
3232
schema: [String]
3333
},
3434
status: { type: String },
35-
finalDetails: { type: Object },
35+
finalDetails: {
36+
type: Object,
37+
schema: {
38+
aggregateScore: Number,
39+
testsPassed: Number,
40+
totalTestCases: Number
41+
}
42+
},
3643
createdAt: {
3744
type: String,
3845
required: true

src/services/LeaderboardService.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ async function updateLeaderboard (challengeId, memberId, review) {
214214
let scoreLevelChanged = false
215215

216216
if (review.resource === 'reviewSummation') {
217+
console.log('Updating leaderboard using review summation')
218+
if (!review.aggregateScore) {
219+
throw Error('Aggregate score is needed for the review summation')
220+
}
217221
_.assignIn(existRecords[0], {
218222
finalDetails: {
219223
aggregateScore: review.aggregateScore,
@@ -222,6 +226,7 @@ async function updateLeaderboard (challengeId, memberId, review) {
222226
}
223227
})
224228
} else {
229+
console.log('Updating leaderboard using review')
225230
if (review.status !== 'queued') {
226231
if (existRecords[0].aggregateScore > review.score) {
227232
scoreLevel = 'down'
@@ -275,7 +280,8 @@ updateLeaderboard.schema = {
275280
memberId: joi.string().required(),
276281
review: joi.object().keys({
277282
id: joi.string().required(),
278-
score: joi.number().required().allow(null)
283+
score: joi.number().allow(null),
284+
aggregateScore: joi.number()
279285
}).unknown(true).required()
280286
}
281287

0 commit comments

Comments
 (0)