Merge branch 'ogzcoder/feat/track-user-submit' into staging

This commit is contained in:
Berkeley Martinez
2017-09-08 00:17:41 -07:00
2 changed files with 12 additions and 4 deletions

View File

@ -182,6 +182,7 @@
{ {
"completedDate": "number", "completedDate": "number",
"lastUpdated": "number", "lastUpdated": "number",
"numOfAttempts": "number",
"id": "string", "id": "string",
"name": "string", "name": "string",
"completedWith": "string", "completedWith": "string",

View File

@ -14,20 +14,24 @@ function buildUserUpdate(
completedChallenge, completedChallenge,
timezone timezone
) { ) {
const updateData = { $set: {} };
let finalChallenge; let finalChallenge;
let numOfAttempts = 1;
const updateData = { $set: {} };
const { timezone: userTimezone, challengeMap = {} } = user; const { timezone: userTimezone, challengeMap = {} } = user;
const oldChallenge = challengeMap[challengeId]; const oldChallenge = challengeMap[challengeId];
const alreadyCompleted = !!oldChallenge; const alreadyCompleted = !!oldChallenge;
if (alreadyCompleted) { if (alreadyCompleted) {
// add data from old challenge // add data from old challenge
if (oldChallenge.numOfAttempts) {
numOfAttempts = oldChallenge.numOfAttempts + 1;
}
finalChallenge = { finalChallenge = {
...completedChallenge, ...completedChallenge,
completedDate: oldChallenge.completedDate, completedDate: oldChallenge.completedDate,
lastUpdated: completedChallenge.completedDate lastUpdated: completedChallenge.completedDate,
numOfAttempts
}; };
} else { } else {
updateData.$push = { updateData.$push = {
@ -36,7 +40,10 @@ function buildUserUpdate(
completedChallenge: challengeId completedChallenge: challengeId
} }
}; };
finalChallenge = completedChallenge; finalChallenge = {
...completedChallenge,
numOfAttempts
};
} }
updateData.$set = { updateData.$set = {