travel comments system added

This commit is contained in:
nau
2016-09-05 20:28:14 +02:00
parent 8e98c356a4
commit cb3d7eabba
4 changed files with 56 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ var travelModel = mongoose.model('travelModel');
var userModel = mongoose.model('userModel');
var joinModel = mongoose.model('joinModel');
var commentModel = mongoose.model('commentModel');
//GET
exports.findAllTravels = function(req, res) {
@@ -107,11 +108,10 @@ exports.deleteTravel = function(req, res) {
/* join */
exports.addJoin = function(req, res) {
var join = new joinModel({
travelId: req.body.travelId,
travelId: req.params.travelId,
joinedUserId: req.body.joinedUserId,
joinedUsername: req.body.joinedUsername,
acceptedUserId: req.body.acceptedUserId,
comment: req.body.comment
acceptedUserId: req.body.acceptedUserId
});
join.save(function(err, join) {
@@ -137,3 +137,37 @@ exports.getJoinsByTravelId = function(req, res) {
});
};
/* comment */
exports.addComment = function(req, res) {
var comment = new commentModel({
travelId: req.params.travelId,
commentUserId: req.body.commentUserId,
commentUsername: req.body.commentUsername,
comment: req.body.comment
});
comment.save(function(err, comment) {
if(err) return res.send(500, err.message);
res.status(200).jsonp(comment);
});
};
exports.getCommentsByTravelId = function(req, res) {
commentModel.find({
travelId: req.params.travelId
}, function(err, comments) {
if (err) throw err;
if (!comments) {
res.json({ success: false, message: 'no comments for travelId' });
} else if (comments) {
// return the information including token as JSON
res.jsonp(comments);
}
});
};