aboutsummaryrefslogtreecommitdiff
path: root/routes/user.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/user.js')
-rw-r--r--routes/user.js44
1 files changed, 39 insertions, 5 deletions
diff --git a/routes/user.js b/routes/user.js
index b771418..3ecdf2e 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -237,6 +237,45 @@ var returnRouter = function(io) {
});
});
+ /**
+ * Serve comment history for page pageNum with commentCount messages as a JSON object
+ * comments are sorted by date.
+ */
+ router.get('/user_profile/comments/:commentCount/:pageNum', loggedIn, isUser, function(req, res, next) {
+ var commentList = [];
+ var commentCount = 0;
+
+ function getComments() {
+ return new Promise(function(resolve, reject) {
+ dbFile.retrieve_userComments_history(req.user.user_name, function (success, object) {
+ if (!success) {
+ // Set status code to client error 400
+ res.writeHead(400, {"Content-Type": "application/json"});
+ console.log('No comments found');
+ resolve(1);
+ } else {
+ if (object.length){
+ commentList = object;
+ }
+ commentCount = object.length;
+ res.writeHead(200, {"Content-Type": "application/json"});
+ resolve(1);
+ }
+ });
+ });
+ }
+
+ getComments().then(function (data) {
+ var commentBox = {
+ commentList : commentList,
+ commentCount : commentCount
+ };
+ var commentBoxJSON = JSON.stringify(commentBox);
+ res.end(commentBoxJSON);
+ });
+
+ });
+
router.get('/resetPassword', loggedOut, function(req, res, next) {
res.render('reset_password', {csrfToken: req.csrfToken(), success: req.session.success, errors: req.session.errors});
req.session.errors = null;
@@ -735,7 +774,6 @@ var returnRouter = function(io) {
var token = buf.toString('hex');
});
-
io.on('connection', function(socket){
socket.on('add_notification', function(data){
console.log("inside the add notification log");
@@ -747,10 +785,6 @@ var returnRouter = function(io) {
});
});
-
-
-
-
return router;