mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-06-25 02:10:09 +02:00
feat(invitation): show invitations count badge in header menu
This commit is contained in:
@@ -107,8 +107,6 @@ exports.list = function (req, res) {
|
||||
exports.update = function (req, res) {
|
||||
var invitation = req.invitation;
|
||||
|
||||
console.log(req.query);
|
||||
|
||||
var countRegisteredEmail = function (callback) {
|
||||
User.count({email: req.query.to_email}, function (err, count) {
|
||||
if (err) {
|
||||
@@ -225,6 +223,50 @@ exports.verifyToken = function (req, res) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* countInvitations
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
exports.countInvitations = function (req, res) {
|
||||
var countMyInvitations = function (callback) {
|
||||
Invitation.count({
|
||||
user: req.user._id,
|
||||
status: 0,
|
||||
expiresat: {$gt: Date.now()}
|
||||
}, function (err, count) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
callback(null, count);
|
||||
}
|
||||
});
|
||||
};
|
||||
var countUsedInvitations = function (callback) {
|
||||
Invitation.count({
|
||||
user: req.user._id,
|
||||
status: 2
|
||||
}, function (err, count) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
callback(null, count);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.parallel([countMyInvitations, countUsedInvitations], function (err, results) {
|
||||
if (err) {
|
||||
return res.status(422).send(err);
|
||||
} else {
|
||||
res.json({
|
||||
countMyInvitations: results[0],
|
||||
countUsedInvitations: results[1]
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Invitation middleware
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user