diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-27 05:20:25 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-27 05:20:25 +0000 |
| commit | 6271b9d13139c1e55118e5f26a3a7bf8caeeb11d (patch) | |
| tree | afa1dd05c2686e534080473fb2693c1d521b49f6 | |
| parent | 95b90345d1d6a2cdf67cdae4b913268c609b2498 (diff) | |
Added exam following
| -rw-r--r-- | routes/user.js | 45 | ||||
| -rw-r--r-- | views/user_profile_alt.hbs | 14 |
2 files changed, 51 insertions, 8 deletions
diff --git a/routes/user.js b/routes/user.js index a54b0fb..b2e25f4 100644 --- a/routes/user.js +++ b/routes/user.js @@ -24,6 +24,7 @@ router.get('/user_profile', loggedIn, isUser, function(req, res, next) { var comments = []; var inbox = []; var error = null; + var follows = []; function getComments() { return new Promise(function(resolve, reject) { dbFile.retrieve_userComments_history(req.user.user_name, function (success, object) { @@ -92,6 +93,48 @@ router.get('/user_profile', loggedIn, isUser, function(req, res, next) { }); } + function getFollows(){ + return new Promise(function(resolve, reject) { + + + + dbFile.retrieveFollows(req.user.user_name, function(success, data){ + req.user.examfollows = []; + req.user.followerCount = data.length; + if(success && data.length){ + var count = 1; + data.forEach(function(item){ + dbFile.get_exam_byID(item, function(success, error, data){ + if(success){ + req.user.examfollows.push(data); + if(count == req.user.followerCount ){ + console.log(req.user.examfollows); + resolve(1); + }else{ + count++; + } + }else{ + console.log("Error: Could not fetch one or more exams;"); + resolve(1); + } + }) + }); + + } else if(success && !data.length){ + resolve(1); + console.log("Success: But no follows found;"); + } + else{ //error + error = data; + console.log(error); + resolve(1); + } + + }); + }); + } + + /*function solutionsCount() { return new Promise(function (resolve, reject) { dbFile.retrieve_userSolutions_history(req.user.username, function (bool, results) { @@ -110,7 +153,7 @@ router.get('/user_profile', loggedIn, isUser, function(req, res, next) { - getComments().then(getMail).then(function (data) { + getComments().then(getMail).then(getFollows).then(function (data) { console.log('got here fere'); res.render('user_profile_alt', {inbox: inbox, error: error, csrfToken: req.csrfToken(), userProfile: true}); }); diff --git a/views/user_profile_alt.hbs b/views/user_profile_alt.hbs index 7a61366..cf657db 100644 --- a/views/user_profile_alt.hbs +++ b/views/user_profile_alt.hbs @@ -88,20 +88,20 @@ </div> </div> <div class="row" id="profile-follows"> - {{# if user.followers }} - <h3>You are being followed by:</h3> + {{# if user.examfollows }} + <h4>Here are the exams you are following:</h4> <div class="col-xs-offset-1 col-sm-offset-3 col-xs-10 col-sm-6"> <table class="table-condensed"> <tbody> - {{# each user.followers}} + {{# each user.examfollows}} <tr> <th> - <img class="img-circle img-responsive" - src="../assets/images/misc/user1.jpeg" alt="avatar"> + <a href="/questions/{{this._id}}">Course Code: {{this.course_code}}</a> </th> <th> - <h4>The Dude</h4> - <p>3 comments</p> + <h4>Term: {{this.term}}</h4> + <p>Year: {{this.year}}</p> + <p>Type: {{this.type}}</p> </th> </tr> |
