mirror of
https://github.com/arnaucube/commonroutesServer.git
synced 2026-02-28 05:26:42 +01:00
notification system fixed
This commit is contained in:
@@ -190,6 +190,24 @@ exports.getUserLikes = function(req, res) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
exports.getNumNotificationsByToken = function(req, res) {
|
||||||
|
userModel.findOne({
|
||||||
|
'token': req.headers['x-access-token']
|
||||||
|
})
|
||||||
|
.lean()
|
||||||
|
.exec(function(err, user) {
|
||||||
|
if (err) return res.send(500, err.message);
|
||||||
|
if (!user) {
|
||||||
|
res.json({
|
||||||
|
success: false,
|
||||||
|
message: 'User not found.'
|
||||||
|
});
|
||||||
|
} else if (user) {
|
||||||
|
|
||||||
|
res.status(200).jsonp(user.notifications);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
exports.getNotifications = function(req, res) {
|
exports.getNotifications = function(req, res) {
|
||||||
userModel.findOne({
|
userModel.findOne({
|
||||||
'token': req.headers['x-access-token']
|
'token': req.headers['x-access-token']
|
||||||
@@ -205,9 +223,9 @@ exports.getNotifications = function(req, res) {
|
|||||||
});
|
});
|
||||||
} else if (user) {
|
} else if (user) {
|
||||||
|
|
||||||
//res.status(200).jsonp(user.notifications);
|
|
||||||
notificationModel.find({
|
notificationModel.find({
|
||||||
'user': user._id
|
'user': user._id,
|
||||||
|
'state': 'pendent'
|
||||||
})
|
})
|
||||||
.lean()
|
.lean()
|
||||||
.exec(function(err, notifications) {
|
.exec(function(err, notifications) {
|
||||||
@@ -218,10 +236,31 @@ exports.getNotifications = function(req, res) {
|
|||||||
message: 'No pendent notifications.'
|
message: 'No pendent notifications.'
|
||||||
});
|
});
|
||||||
} else if (notifications) {
|
} else if (notifications) {
|
||||||
|
//here, maybe in the future is better delete the viewed notifications
|
||||||
|
notificationModel.update(
|
||||||
|
{state: "pendent"},
|
||||||
|
{state: "viewed"},
|
||||||
|
{multi: true},
|
||||||
|
function(err){
|
||||||
|
if(err){
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
res.status(200).jsonp(notifications);
|
res.status(200).jsonp(notifications);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//now, clean notifications count from user
|
||||||
|
userModel.update(
|
||||||
|
{'token': req.headers['x-access-token']},
|
||||||
|
{notifications: []},
|
||||||
|
function(err){
|
||||||
|
if(err){
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ apiRoutes.use(function(req, res, next) {
|
|||||||
|
|
||||||
apiRoutes.route('/search/:searchstring')
|
apiRoutes.route('/search/:searchstring')
|
||||||
.get(searchCtrl.searchByString);
|
.get(searchCtrl.searchByString);
|
||||||
|
apiRoutes.route('/numnotifications')
|
||||||
|
.get(userCtrl.getNumNotificationsByToken);
|
||||||
apiRoutes.route('/notifications')
|
apiRoutes.route('/notifications')
|
||||||
.get(userCtrl.getNotifications);
|
.get(userCtrl.getNotifications);
|
||||||
apiRoutes.route('/users/token')
|
apiRoutes.route('/users/token')
|
||||||
|
|||||||
Reference in New Issue
Block a user