Convert model instance to POJO earilier in migration change

This commit is contained in:
Berkeley Martinez
2016-02-10 16:45:57 -08:00
parent 0354eeae16
commit c2915f9e14

View File

@ -22,10 +22,6 @@ const challengeTypeRegWithColon =
/^(bonfire|checkpoint|waypoint|hike|zipline|basejump):\s+/i;
function updateName(challenge) {
challenge = challenge && typeof challenge.toJSON === 'function' ?
challenge.toJSON() :
challenge;
if (
challenge.name &&
challenge.challengeType === 5 &&
@ -57,6 +53,7 @@ function updateId(challenge) {
if (idMap.hasOwnProperty(challenge.id)) {
challenge.id = idMap[challenge.id];
}
return challenge;
}
@ -72,6 +69,11 @@ function buildChallengeMap(userId, completedChallenges = [], User) {
null,
Scheduler.default
)
.map(challenge => {
return challenge && typeof challenge.toJSON === 'function' ?
challenge.toJSON() :
challenge;
})
.map(updateId)
.filter(({ id, _id }) => ObjectID.isValid(id || _id))
.map(updateName)