added user._id on notification
arnaucode idoctnef@openmailbox.org
Mon, 19 Jun 2017 22:21:26 +0200
3 files changed,
33 insertions(+),
14 deletions(-)
M
controllers/travelController.js
→
controllers/travelController.js
@@ -6,7 +6,7 @@ var travelModel = mongoose.model('travelModel');
var commentModel = mongoose.model('commentModel'); //GET -var pageSize=2; +var pageSize=20; exports.getAllTravels = function(req, res) { //get travels with futures dates ($gte - greater than and equal than) travelModel.find({date: {$gte: new Date()}})@@ -151,7 +151,8 @@ concept: "join",
message: "user "+userJoining.username+" joins your travel "+travel.title, date: new Date(), icon: 'join.png', - link: "travels/" + travel._id + link: "travels/" + travel._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -209,7 +210,8 @@ concept: "unjoin",
message: "user "+userJoining.username+" unjoins your travel "+travel.title, date: new Date(), icon: 'unjoin.png', - link: "travels/" + travel._id + link: "travels/" + travel._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -277,7 +279,8 @@ concept: "travel",
message: "user "+userOwner.username+" declines your petition for "+travel.title, date: new Date(), icon: 'travel.png', - link: "travels/" + travel._id + link: "travels/" + travel._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -345,7 +348,8 @@ concept: "travel",
message: "user "+userOwner.username+" accepts your petition for "+travel.title, date: new Date(), icon: 'travel.png', - link: "travels/" + travel._id + link: "travels/" + travel._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -403,7 +407,8 @@ concept: "leave",
message: "user "+userLeaving.username+" leaves your travel "+travel.title, date: new Date(), icon: 'leave.png', - link: "travels/" + travel._id + link: "travels/" + travel._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -479,7 +484,8 @@ concept: "comment",
otherusername: user.username, description: "user "+user.username+" comments your travel "+travel.title, date: new Date(), - link: "" + link: "", + user: userowners[0]._id }; userowner.notifications.push(notification); userowner.save(function(err, userowner) {
M
controllers/userController.js
→
controllers/userController.js
@@ -187,7 +187,18 @@ if (!user) {
res.json({success: false, message: 'User not found.'}); } else if (user) { - res.status(200).jsonp(user.notifications); + //res.status(200).jsonp(user.notifications); + notificationModel.find({'user': user._id}) + .lean() + .exec(function (err, notifications) { + if (err) return res.send(500, err.message); + if (!notifications) { + res.json({success: false, message: 'No pendent notifications.'}); + } else if (notifications) { + + res.status(200).jsonp(notifications); + } + }); } }); };@@ -233,7 +244,8 @@ concept: "like",
message: "user "+userL.username+" adds a like to you", date: new Date(), icon: 'like.png', - link: "users/" + user._id + link: "users/" + user._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -275,7 +287,8 @@ concept: "like",
message: "user "+userL.username+" removes like on you", date: new Date(), icon: 'like.png', - link: "users/" + user._id + link: "users/" + user._id, + user: user._id }); notification.save(function(err, notification) { if (err) return res.send(500, err.message);@@ -328,7 +341,8 @@ concept: "like",
otherusername: tokenuser.username, description: "user " + tokenuser.username + " favs you", date: new Date(), - link: "" + link: "", + user: user._id }; user.notifications.push(notification);
M
package.json
→
package.json
@@ -1,12 +1,11 @@
{ - "name": "comunalCar", + "name": "CarsInCommon", "version": "0.0.1", - "description": "comunalCar, carsharing", + "description": "CarsInCommon, cooperative carsharing", "repository": "https://github.com/arnaucode/carsincommonServer", "contributors": [ { "name": "Arnau", - "email": "idoctnef@openmailbox.org", "web": "arnaucode.com" } ],