Browse Source

notification system almost implemented on backend

master
arnaucode 8 years ago
parent
commit
241f92770c
4 changed files with 71 additions and 1 deletions
  1. +6
    -0
      README.md
  2. +44
    -0
      controllers/travelController.js
  3. +14
    -1
      controllers/userController.js
  4. +7
    -0
      models/userModel.js

+ 6
- 0
README.md

@ -56,6 +56,12 @@ frontend app code: https://github.com/idoctnef/collectivecarApp
-es veu el telèfon dels users? -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? -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
``` ```

+ 44
- 0
controllers/travelController.js

@ -167,6 +167,8 @@ exports.addJoin = function(req, res) {
}; };
travel.joins.push(join); travel.joins.push(join);
travel.save(function(err, travel) { travel.save(function(err, travel) {
if(err) return res.send(500, err.message); if(err) return res.send(500, err.message);
//res.status(200).jsonp(travel); //res.status(200).jsonp(travel);
@ -175,7 +177,28 @@ exports.addJoin = function(req, res) {
res.status(200).jsonp(travels); 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 @@ exports.doUnjoin = function(req, res) {
res.status(200).jsonp(travels); res.status(200).jsonp(travels);
}); });
}); });
}); });
}); });
}; };
@ -262,6 +286,26 @@ exports.addComment = function(req, res) {
res.status(200).jsonp(travels); 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 });//end of userModel.find
}; };

+ 14
- 1
controllers/userController.js

@ -127,6 +127,7 @@ exports.addFav = function(req, res) {
console.log("favRepeated: " + favRepeated); console.log("favRepeated: " + favRepeated);
if(favRepeated==false) if(favRepeated==false)
{ {
//fav
var fav = { var fav = {
userId: tokenuser._id, userId: tokenuser._id,
username: tokenuser.username, username: tokenuser.username,
@ -134,9 +135,21 @@ exports.addFav = function(req, res) {
}; };
user.favs.push(fav); 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) { user.save(function(err, user) {
if(err) return res.send(500, err.message); 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) { userModel.find(function(err, users) {
if(err) res.send(500, err.message); if(err) res.send(500, err.message);
res.status(200).jsonp(users); res.status(200).jsonp(users);

+ 7
- 0
models/userModel.js

@ -22,6 +22,13 @@ var userSchema = new Schema({
username: { type: String }, username: { type: String },
userId: { type: String }, userId: { type: String },
avatar: { type: String } avatar: { type: String }
}],
notifications: [{
type: { type: String },//fav, comment, join
otherusername: { type: String },
description: { type: String },
date: { type: Date },
link: { type: String }
}] }]
}) })

Loading…
Cancel
Save