fix(updated): Update completedChallenges and progressTimestamps without duplicates (#17226)

Closes #17200
This commit is contained in:
Stuart Taylor
2018-05-24 14:59:46 +01:00
committed by mrugesh mohapatra
parent 58a5d0d181
commit 3e52c666da
2 changed files with 34 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ function buildUserUpdate(
timezone
) {
let finalChallenge;
const updateData = { $push: {} };
const updateData = {};
const { timezone: userTimezone, completedChallenges = [] } = user;
const oldChallenge = _.find(
@@ -44,9 +44,11 @@ function buildUserUpdate(
};
}
updateData.$push = {
...updateData.$push,
completedChallenges: finalChallenge
updateData.$set = {
completedChallenges: _.uniqBy(
[finalChallenge, ...completedChallenges],
'id'
)
};
if (