From 6271b9d13139c1e55118e5f26a3a7bf8caeeb11d Mon Sep 17 00:00:00 2001 From: HumairAK Date: Wed, 27 Jul 2016 01:20:25 -0400 Subject: Added exam following --- routes/user.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 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 @@
- {{# if user.followers }} -

You are being followed by:

+ {{# if user.examfollows }} +

Here are the exams you are following:

- {{# each user.followers}} + {{# each user.examfollows}} -- cgit v1.2.3
- avatar + Course Code: {{this.course_code}} -

The Dude

-

3 comments

+

Term: {{this.term}}

+

Year: {{this.year}}

+

Type: {{this.type}}