From 29091426a48964471c5a97e813c7f7ca859ce03d Mon Sep 17 00:00:00 2001 From: idoctnef Date: Thu, 6 Oct 2016 22:40:54 +0200 Subject: [PATCH] user fav system implemented --- config.js | 8 +++--- controllers/userController.js | 46 ++++++++++++++++++++++++++++++++++- models/userModel.js | 5 ++++ server.js | 5 ++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/config.js b/config.js index d0108f3..7b004bc 100644 --- a/config.js +++ b/config.js @@ -1,8 +1,8 @@ module.exports = { - /*'secret': process.env.SECRET,// production version - 'database': process.env.MONGO_DSN,*/ - 'secret': 'secretfortoken',// local version - 'database': 'mongodb://localhost/comunalcar', + 'secret': process.env.SECRET,// production version + 'database': process.env.MONGO_DSN, + /*'secret': 'secretfortoken',// local version + 'database': 'mongodb://localhost/comunalcar',*/ "port" : process.env.PORT || 3000 }; diff --git a/controllers/userController.js b/controllers/userController.js index 9e86f43..f914fd0 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -86,6 +86,48 @@ exports.addUser = function(req, res) { }); }; +/* fav */ +exports.addFav = function(req, res) { + userModel.findById(req.params.userId, function(err, user){ + var fav = { + userId: req.body.userId, + username: req.body.username, + avatar: req.body.avatar + }; + user.favs.push(fav); + + user.save(function(err, user) { + if(err) return res.send(500, err.message); + //res.status(200).jsonp(travel); + userModel.find(function(err, users) { + if(err) res.send(500, err.message); + res.status(200).jsonp(users); + }); + }); + }); +}; +exports.doUnfav = function(req, res) { + + userModel.findById(req.params.userId, function(err, user){ + for(var i=0; i