Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Don't show offline badges on badge index.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianloveswords committed Nov 11, 2012
1 parent dd4a4f3 commit 522f93d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app.js
Expand Up @@ -66,7 +66,7 @@ app.post('/admin/config', issuer.update);
// Badge listing
// -------------
var indexMiddleware = [badge.findAll, behavior.findAll];
app.get('/', badge.findAll, admin.all);
app.get('/', badge.findNonOffline, admin.all);
app.get('/admin', indexMiddleware, admin.badgeIndex);
app.get('/admin/badges', indexMiddleware, admin.badgeIndex);

Expand Down
21 changes: 17 additions & 4 deletions routes/badge.js
Expand Up @@ -182,6 +182,7 @@ exports.findByClaimCode = function findByClaimCode(options) {
}
};

// #TODO: refactor the following three fuctions into just one, probably
exports.findByShortName = function (options) {
var required = !!options.required;

Expand Down Expand Up @@ -210,10 +211,22 @@ exports.findByShortName = function (options) {

exports.findAll = function findAll(req, res, next) {
Badge.find({}, function (err, badges) {
// #TODO: don't show the error directly
if (err)
return res.send(500, err);
if (err) return next(err)
req.badges = badges;
return next();
});
};

exports.findNonOffline = function findNonOffline(req, res, next) {
var query = {
'$or': [
{claimCodes: {'$exists': false }} ,
{claimCodes: {'$size': 0 }}
]
};
Badge.find(query, function (err, badges) {
if (err) return next(err);
req.badges = badges;
next();
return next();
});
};

0 comments on commit 522f93d

Please sign in to comment.