mirror of
https://github.com/arnaucube/commonroutesServer.git
synced 2026-02-28 05:26:42 +01:00
added user._id on notification
This commit is contained in:
@@ -6,7 +6,7 @@ var travelModel = mongoose.model('travelModel');
|
|||||||
var commentModel = mongoose.model('commentModel');
|
var commentModel = mongoose.model('commentModel');
|
||||||
|
|
||||||
//GET
|
//GET
|
||||||
var pageSize=2;
|
var pageSize=20;
|
||||||
exports.getAllTravels = function(req, res) {
|
exports.getAllTravels = function(req, res) {
|
||||||
//get travels with futures dates ($gte - greater than and equal than)
|
//get travels with futures dates ($gte - greater than and equal than)
|
||||||
travelModel.find({date: {$gte: new Date()}})
|
travelModel.find({date: {$gte: new Date()}})
|
||||||
@@ -151,7 +151,8 @@ exports.addJoinPetition = function(req, res) {
|
|||||||
message: "user "+userJoining.username+" joins your travel "+travel.title,
|
message: "user "+userJoining.username+" joins your travel "+travel.title,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'join.png',
|
icon: 'join.png',
|
||||||
link: "travels/" + travel._id
|
link: "travels/" + travel._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -209,7 +210,8 @@ exports.unJoin = function(req, res) {
|
|||||||
message: "user "+userJoining.username+" unjoins your travel "+travel.title,
|
message: "user "+userJoining.username+" unjoins your travel "+travel.title,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'unjoin.png',
|
icon: 'unjoin.png',
|
||||||
link: "travels/" + travel._id
|
link: "travels/" + travel._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -277,7 +279,8 @@ exports.declineJoin = function(req, res) {
|
|||||||
message: "user "+userOwner.username+" declines your petition for "+travel.title,
|
message: "user "+userOwner.username+" declines your petition for "+travel.title,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'travel.png',
|
icon: 'travel.png',
|
||||||
link: "travels/" + travel._id
|
link: "travels/" + travel._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -345,7 +348,8 @@ exports.acceptJoin = function(req, res) {
|
|||||||
message: "user "+userOwner.username+" accepts your petition for "+travel.title,
|
message: "user "+userOwner.username+" accepts your petition for "+travel.title,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'travel.png',
|
icon: 'travel.png',
|
||||||
link: "travels/" + travel._id
|
link: "travels/" + travel._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -403,7 +407,8 @@ exports.leave = function(req, res) {
|
|||||||
message: "user "+userLeaving.username+" leaves your travel "+travel.title,
|
message: "user "+userLeaving.username+" leaves your travel "+travel.title,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'leave.png',
|
icon: 'leave.png',
|
||||||
link: "travels/" + travel._id
|
link: "travels/" + travel._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -479,7 +484,8 @@ exports.addComment = function(req, res) {
|
|||||||
otherusername: user.username,
|
otherusername: user.username,
|
||||||
description: "user "+user.username+" comments your travel "+travel.title,
|
description: "user "+user.username+" comments your travel "+travel.title,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
link: ""
|
link: "",
|
||||||
|
user: userowners[0]._id
|
||||||
};
|
};
|
||||||
userowner.notifications.push(notification);
|
userowner.notifications.push(notification);
|
||||||
userowner.save(function(err, userowner) {
|
userowner.save(function(err, userowner) {
|
||||||
|
|||||||
@@ -187,7 +187,18 @@ exports.getNotifications = function (req, res) {
|
|||||||
res.json({success: false, message: 'User not found.'});
|
res.json({success: false, message: 'User not found.'});
|
||||||
} else if (user) {
|
} 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 @@ exports.likeUser = function(req, res) {
|
|||||||
message: "user "+userL.username+" adds a like to you",
|
message: "user "+userL.username+" adds a like to you",
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'like.png',
|
icon: 'like.png',
|
||||||
link: "users/" + user._id
|
link: "users/" + user._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -275,7 +287,8 @@ exports.unlikeUser = function(req, res) {
|
|||||||
message: "user "+userL.username+" removes like on you",
|
message: "user "+userL.username+" removes like on you",
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
icon: 'like.png',
|
icon: 'like.png',
|
||||||
link: "users/" + user._id
|
link: "users/" + user._id,
|
||||||
|
user: user._id
|
||||||
});
|
});
|
||||||
notification.save(function(err, notification) {
|
notification.save(function(err, notification) {
|
||||||
if (err) return res.send(500, err.message);
|
if (err) return res.send(500, err.message);
|
||||||
@@ -328,7 +341,8 @@ exports.addFav = function(req, res) {
|
|||||||
otherusername: tokenuser.username,
|
otherusername: tokenuser.username,
|
||||||
description: "user " + tokenuser.username + " favs you",
|
description: "user " + tokenuser.username + " favs you",
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
link: ""
|
link: "",
|
||||||
|
user: user._id
|
||||||
};
|
};
|
||||||
user.notifications.push(notification);
|
user.notifications.push(notification);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "comunalCar",
|
"name": "CarsInCommon",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "comunalCar, carsharing",
|
"description": "CarsInCommon, cooperative carsharing",
|
||||||
"repository": "https://github.com/arnaucode/carsincommonServer",
|
"repository": "https://github.com/arnaucode/carsincommonServer",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
{
|
||||||
"name": "Arnau",
|
"name": "Arnau",
|
||||||
"email": "idoctnef@openmailbox.org",
|
|
||||||
"web": "arnaucode.com"
|
"web": "arnaucode.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user