notification system almost implemented on backend
arnaucode idoctnef@openmailbox.org
Tue, 18 Oct 2016 13:19:04 +0200
4 files changed,
71 insertions(+),
1 deletions(-)
M
README.md
→
README.md
@@ -56,6 +56,12 @@ que es podrà fer servir des d'un navegador com si fós la app)
-es veu el telèfon dels users? -com evitem q algú xungu es registri a la app i vegi els viatges i info dels users? + + +-falta acabar notification system + quan mires les notificacions, que avisi al server q ja les has vist, i que el server les marqui com a llegides + link a les notificacions + acabar de mirar q a la app, quan agafa els users del server, tingui actualitzades les notificacions del user al menu ```
M
controllers/travelController.js
→
controllers/travelController.js
@@ -167,6 +167,8 @@ joinedAvatar: user.avatar
}; travel.joins.push(join); + + travel.save(function(err, travel) { if(err) return res.send(500, err.message); //res.status(200).jsonp(travel);@@ -175,7 +177,28 @@ if(err) res.send(500, err.message);
res.status(200).jsonp(travels); }); }); + + //start saving notification, get user owner of travel + userModel.find({ + username: travel.owner + }, function(err, userowners) { + var userowner=userowners[0]; + //notification + var notification = { + type: "join", + otherusername: user.username, + description: "user "+user.username+" joins your travel "+travel.title, + date: new Date(), + link: "" + }; + userowner.notifications.push(notification); + userowner.save(function(err, userowner) { + console.log("notification saved"); + }); + });//end saving notification + }); + }); };@@ -202,6 +225,7 @@ if(err) res.send(500, err.message);
res.status(200).jsonp(travels); }); }); + }); }); };@@ -262,6 +286,26 @@ if(err) res.send(500, err.message);
res.status(200).jsonp(travels); }); }); + + //start saving notification, get user owner of travel + userModel.find({ + username: travel.owner + }, function(err, userowners) { + var userowner=userowners[0]; + //notification + var notification = { + type: "comment", + otherusername: user.username, + description: "user "+user.username+" comments your travel "+travel.title, + date: new Date(), + link: "" + }; + userowner.notifications.push(notification); + userowner.save(function(err, userowner) { + console.log("notification saved"); + }); + });//end saving notification + }); });//end of userModel.find };
M
controllers/userController.js
→
controllers/userController.js
@@ -127,6 +127,7 @@ }
console.log("favRepeated: " + favRepeated); if(favRepeated==false) { + //fav var fav = { userId: tokenuser._id, username: tokenuser.username,@@ -134,9 +135,21 @@ avatar: tokenuser.avatar
}; user.favs.push(fav); + //notification + var notification = { + type: "fav", + otherusername: tokenuser.username, + description: "user "+tokenuser.username+" favs you", + date: new Date(), + link: "" + }; + user.notifications.push(notification); + user.save(function(err, user) { if(err) return res.send(500, err.message); - //res.status(200).jsonp(travel); + + + //once saved, send the users json to client userModel.find(function(err, users) { if(err) res.send(500, err.message); res.status(200).jsonp(users);
M
models/userModel.js
→
models/userModel.js
@@ -22,6 +22,13 @@ favs: [{
username: { type: String }, userId: { type: String }, avatar: { type: String } + }], + notifications: [{ + type: { type: String },//fav, comment, join + otherusername: { type: String }, + description: { type: String }, + date: { type: Date }, + link: { type: String } }] })