Convert model instance to POJO earilier in migration change
This commit is contained in:
@ -22,10 +22,6 @@ const challengeTypeRegWithColon =
|
|||||||
/^(bonfire|checkpoint|waypoint|hike|zipline|basejump):\s+/i;
|
/^(bonfire|checkpoint|waypoint|hike|zipline|basejump):\s+/i;
|
||||||
|
|
||||||
function updateName(challenge) {
|
function updateName(challenge) {
|
||||||
challenge = challenge && typeof challenge.toJSON === 'function' ?
|
|
||||||
challenge.toJSON() :
|
|
||||||
challenge;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
challenge.name &&
|
challenge.name &&
|
||||||
challenge.challengeType === 5 &&
|
challenge.challengeType === 5 &&
|
||||||
@ -57,6 +53,7 @@ function updateId(challenge) {
|
|||||||
if (idMap.hasOwnProperty(challenge.id)) {
|
if (idMap.hasOwnProperty(challenge.id)) {
|
||||||
challenge.id = idMap[challenge.id];
|
challenge.id = idMap[challenge.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
return challenge;
|
return challenge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,6 +69,11 @@ function buildChallengeMap(userId, completedChallenges = [], User) {
|
|||||||
null,
|
null,
|
||||||
Scheduler.default
|
Scheduler.default
|
||||||
)
|
)
|
||||||
|
.map(challenge => {
|
||||||
|
return challenge && typeof challenge.toJSON === 'function' ?
|
||||||
|
challenge.toJSON() :
|
||||||
|
challenge;
|
||||||
|
})
|
||||||
.map(updateId)
|
.map(updateId)
|
||||||
.filter(({ id, _id }) => ObjectID.isValid(id || _id))
|
.filter(({ id, _id }) => ObjectID.isValid(id || _id))
|
||||||
.map(updateName)
|
.map(updateName)
|
||||||
|
Reference in New Issue
Block a user