aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/user.js45
-rw-r--r--views/user_profile_alt.hbs14
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>