Ensure all bonfires have names in account profile view. Add more aptly names state flag for future user data massaging.

This commit is contained in:
terakilobyte
2015-05-05 16:12:53 -04:00
parent 1df3b2671b
commit b73c7eac62
3 changed files with 42 additions and 5 deletions

View File

@ -25,7 +25,8 @@ var async = require('async'),
* Cached values * Cached values
*/ */
var allBonfireIds, allBonfireNames, allCoursewareIds, allCoursewareNames, var allBonfireIds, allBonfireNames, allCoursewareIds, allCoursewareNames,
allFieldGuideIds, allFieldGuideNames, allNonprofitNames; allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
allBonfireIndexesAndNames;
/** /**
* GET / * GET /
@ -305,6 +306,31 @@ module.exports = {
} }
}, },
bonfiresIndexesAndNames: function() {
if (allBonfireIndexesAndNames) {
return allBonfireIndexesAndNames
} else {
var obj = {};
bonfires.forEach(function(elem) {
obj[elem._id] = elem.name;
});
allBonfireIndexesAndNames = obj;
return allBonfireIndexesAndNames;
}
},
ensureBonfireNames: function(completedBonfires) {
return completedBonfires.map(function(elem) {
return ({
name: this.bonfiresIndexesAndNames()[elem._id],
_id: elem.id,
completedDate: elem.completedDate,
completedWith: elem.completedWith,
solution: elem.solution
});
}.bind(this));
},
allFieldGuideIds: function() { allFieldGuideIds: function() {
if (allFieldGuideIds) { if (allFieldGuideIds) {
return allFieldGuideIds; return allFieldGuideIds;

View File

@ -299,7 +299,7 @@ exports.returnUser = function(req, res, next) {
var today = moment(Date.now()), currStreak = 1; var today = moment(Date.now()), currStreak = 1;
if (moment(timeKeys[0]).add(1, 'd').toString === today.toString()) { if (moment(timeKeys[0]).add(1, 'd').toString === today.toString()) {
for (var i = 2; i <= timeKeys.length; i++) { for (var i = 2; i <= timeKeys.length; i++) {
if (moment(timeKeys[i-1]).add(1, 'd').toString() if (moment(timeKeys[i - 1]).add(1, 'd').toString()
=== moment(timeKeys[i]).toString()) { === moment(timeKeys[i]).toString()) {
currStreak++; currStreak++;
} else { } else {
@ -321,9 +321,17 @@ exports.returnUser = function(req, res, next) {
data[(timeStamp / 1000)] = 1; data[(timeStamp / 1000)] = 1;
}); });
//for (var i = 0; i < progressTimestamps.length; i++) { if (!user.needsMigration) {
// data[(progressTimestamps[i] / 1000).toString()] = 1; var currentlySolvedBonfires = user.completedBonfires;
//} user.completedBonfires =
resources.ensureBonfireNames(currentlySolvedBonfires);
user.needsMigration = true;
user.save(function(err) {
if (err) {
return next(err);
}
});
}
user.currentStreak = user.currentStreak || 1; user.currentStreak = user.currentStreak || 1;
user.longestStreak = user.longestStreak || 1; user.longestStreak = user.longestStreak || 1;

View File

@ -139,6 +139,9 @@ var userSchema = new mongoose.Schema({
type: Number, type: Number,
default: 0 default: 0
}, },
needsSomeDataModeled: { type: Boolean, default: false},
// needsMigration has been deprecated, use needsSomeDataModeled
needsMigration: { type: Boolean, default: true }, needsMigration: { type: Boolean, default: true },
finishedWaypoints: { type: Boolean, default: false }, finishedWaypoints: { type: Boolean, default: false },
sendMonthlyEmail: { type: Boolean, default: true }, sendMonthlyEmail: { type: Boolean, default: true },