Migration script written.
This commit is contained in:
@ -248,7 +248,6 @@ exports.returnIndividualChallenge = function(req, res, next) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
5: function() {
|
5: function() {
|
||||||
debug('challenge MDNLinks', challenge.MDNlinks);
|
|
||||||
res.render('bonfire/show', {
|
res.render('bonfire/show', {
|
||||||
completedWith: null,
|
completedWith: null,
|
||||||
title: challenge.name,
|
title: challenge.name,
|
||||||
@ -291,7 +290,6 @@ exports.completedBonfire = function (req, res, next) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
} else {
|
} else {
|
||||||
var index = req.user.uncompletedChallenges.indexOf(challengeId);
|
var index = req.user.uncompletedChallenges.indexOf(challengeId);
|
||||||
debug('This is the index', index);
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
req.user.progressTimestamps.push(Date.now() || 0);
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
req.user.uncompletedChallenges.splice(index, 1);
|
req.user.uncompletedChallenges.splice(index, 1);
|
||||||
@ -299,7 +297,6 @@ exports.completedBonfire = function (req, res, next) {
|
|||||||
pairedWith = pairedWith.pop();
|
pairedWith = pairedWith.pop();
|
||||||
|
|
||||||
index = pairedWith.uncompletedChallenges.indexOf(challengeId);
|
index = pairedWith.uncompletedChallenges.indexOf(challengeId);
|
||||||
debug('This is the index of the search for bonfire', index);
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
pairedWith.progressTimestamps.push(Date.now() || 0);
|
pairedWith.progressTimestamps.push(Date.now() || 0);
|
||||||
pairedWith.uncompletedChallenges.splice(index, 1);
|
pairedWith.uncompletedChallenges.splice(index, 1);
|
||||||
@ -350,8 +347,6 @@ exports.completedBonfire = function (req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var index = req.user.uncompletedChallenges.indexOf(challengeId);
|
var index = req.user.uncompletedChallenges.indexOf(challengeId);
|
||||||
debug('this is the challengeId we got', challengeId);
|
|
||||||
debug('This is the index of the search for bonfire', index);
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
|
||||||
req.user.progressTimestamps.push(Date.now() || 0);
|
req.user.progressTimestamps.push(Date.now() || 0);
|
||||||
|
@ -333,18 +333,6 @@ exports.returnUser = function(req, res, next) {
|
|||||||
data[(timeStamp / 1000)] = 1;
|
data[(timeStamp / 1000)] = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user.needsMigration) {
|
|
||||||
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;
|
||||||
var challenges = user.completedCoursewares.filter(function ( obj ) {
|
var challenges = user.completedCoursewares.filter(function ( obj ) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
/*eslint-disable block-scoped-var */
|
||||||
require('dotenv').load();
|
require('dotenv').load();
|
||||||
var mongodb = require('mongodb'),
|
var User = require('../models/User.js'),
|
||||||
User = require('../models/User.js'),
|
secrets = require('../config/secrets'),
|
||||||
newChallenges = require('./challengeMapping.json'),
|
mongoose = require('mongoose'),
|
||||||
secrets = require('../config/secrets');
|
R = require('ramda');
|
||||||
mongoose = require('mongoose');
|
|
||||||
|
|
||||||
mongoose.connect(secrets.db);
|
mongoose.connect(secrets.db);
|
||||||
|
|
||||||
@ -57,6 +57,7 @@ function userModelMigration(cb) {
|
|||||||
|
|
||||||
stream.on('data', function (user) {
|
stream.on('data', function (user) {
|
||||||
console.log(i++);
|
console.log(i++);
|
||||||
|
/*
|
||||||
if (user.challengesHash) {
|
if (user.challengesHash) {
|
||||||
this.pause();
|
this.pause();
|
||||||
user.needsMigration = false;
|
user.needsMigration = false;
|
||||||
@ -88,6 +89,25 @@ function userModelMigration(cb) {
|
|||||||
user.progressTimestamps.push(bonfire.completedDate);
|
user.progressTimestamps.push(bonfire.completedDate);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
user.needsMigration = false;
|
||||||
|
user.completedChallenges = R.filter(function(elem) {
|
||||||
|
return elem; // getting rid of undefined
|
||||||
|
}, R.concat(
|
||||||
|
user.completedCoursewares,
|
||||||
|
user.completedBonfires.map(function(bonfire) {
|
||||||
|
return ({
|
||||||
|
completedDate: bonfire.completedDate,
|
||||||
|
_id: bonfire._id,
|
||||||
|
name: bonfire.name,
|
||||||
|
completedWith: bonfire.completedWith,
|
||||||
|
solution: bonfire.solution,
|
||||||
|
githubLink: '',
|
||||||
|
verified: false,
|
||||||
|
challengeType: 5
|
||||||
|
});
|
||||||
|
})
|
||||||
|
));
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
user.save(function (err) {
|
user.save(function (err) {
|
||||||
|
Reference in New Issue
Block a user