diff --git a/common/models/user.json b/common/models/user.json index 5874419451..521b36f9bf 100644 --- a/common/models/user.json +++ b/common/models/user.json @@ -182,6 +182,7 @@ { "completedDate": "number", "lastUpdated": "number", + "numOfAttempts": "number", "id": "string", "name": "string", "completedWith": "string", diff --git a/server/boot/challenge.js b/server/boot/challenge.js index fb7da84af7..609d05412b 100644 --- a/server/boot/challenge.js +++ b/server/boot/challenge.js @@ -14,20 +14,24 @@ function buildUserUpdate( completedChallenge, timezone ) { - const updateData = { $set: {} }; let finalChallenge; + let numOfAttempts = 1; + const updateData = { $set: {} }; const { timezone: userTimezone, challengeMap = {} } = user; const oldChallenge = challengeMap[challengeId]; const alreadyCompleted = !!oldChallenge; - if (alreadyCompleted) { // add data from old challenge + if (oldChallenge.numOfAttempts) { + numOfAttempts = oldChallenge.numOfAttempts + 1; + } finalChallenge = { ...completedChallenge, completedDate: oldChallenge.completedDate, - lastUpdated: completedChallenge.completedDate + lastUpdated: completedChallenge.completedDate, + numOfAttempts }; } else { updateData.$push = { @@ -36,7 +40,10 @@ function buildUserUpdate( completedChallenge: challengeId } }; - finalChallenge = completedChallenge; + finalChallenge = { + ...completedChallenge, + numOfAttempts + }; } updateData.$set = {