Browse Source

comments inside travel json

master
idoctnef 8 years ago
parent
commit
408812b265
3 changed files with 26 additions and 21 deletions
  1. +4
    -4
      config.js
  2. +21
    -16
      controllers/travelController.js
  3. +1
    -1
      server.js

+ 4
- 4
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
};

+ 21
- 16
controllers/travelController.js

@ -135,22 +135,7 @@ exports.addJoin = function(req, res) {
};
exports.doUnjoin = function(req, res) {
/*joinModel.find({
travelId: req.params.travelId
}, function(err, joins) {
for(var i=0; i<joins.length; i++)
{
if(joins[i].joinedUsername==req.body.joinedUsername)
{
joins[i].remove(function(err) {
if(err) return res.send(500, err.message);
res.status(200).jsonp('removed');
console.log('DELETE /unjoin/' + req.params.id);
})
}
}
});*/
travelModel.findById(req.params.travelId, function(err, travel){
for(var i=0; i<travel.joins.length; i++)
{
@ -192,7 +177,7 @@ exports.getJoinsByTravelId = function(req, res) {
/* comment */
exports.addComment = function(req, res) {
var comment = new commentModel({
/*var comment = new commentModel({
travelId: req.params.travelId,
commentUserId: req.body.commentUserId,
commentUsername: req.body.commentUsername,
@ -203,6 +188,26 @@ exports.addComment = function(req, res) {
comment.save(function(err, comment) {
if(err) return res.send(500, err.message);
res.status(200).jsonp(comment);
});*/
travelModel.findById(req.params.travelId, function(err, travel){
console.log(travel.title);
var comment = {
commentUserId: req.body.commentUserId,
commentUsername: req.body.commentUsername,
comment: req.body.comment,
commentAvatar: req.body.commentAvatar
};
travel.comments.push(comment);
travel.save(function(err, travel) {
if(err) return res.send(500, err.message);
//res.status(200).jsonp(travel);
travelModel.find(function(err, travels) {
if(err) res.send(500, err.message);
res.status(200).jsonp(travels);
});
});
});
};

+ 1
- 1
server.js

@ -132,7 +132,7 @@ apiRoutes.route('/travels/:travelId/join')
apiRoutes.route('/travels/:travelId/unjoin')
.post(travelCtrl.doUnjoin);
apiRoutes.route('/travels/comment/:travelId')
apiRoutes.route('/travels/:travelId/comment')
.post(travelCtrl.addComment);
app.use('/api', apiRoutes);

Loading…
Cancel
Save