Added _isMember to APIv2 challenges/:cid endpoint (requires user auth)

This commit is contained in:
Kevin Gisi
2015-03-28 02:49:56 -04:00
parent 3e653c9282
commit 79fe0b53c5
2 changed files with 6 additions and 1 deletions

View File

@@ -56,6 +56,7 @@ api.list = function(req, res, next) {
// GET
api.get = function(req, res, next) {
var user = res.locals.user;
// TODO use mapReduce() or aggregate() here to
// 1) Find the sum of users.tasks.values within the challnege (eg, {'profile.name':'tyler', 'sum': 100})
// 2) Sort by the sum
@@ -65,8 +66,11 @@ api.get = function(req, res, next) {
.exec(function(err, challenge){
if(err) return next(err);
if (!challenge) return res.json(404, {err: 'Challenge ' + req.params.cid + ' not found'});
challenge._isMember = !!(_.find(challenge.members, function(member) {
return member._id === user._id;
}));
res.json(challenge);
})
});
}
api.csv = function(req, res, next) {

View File

@@ -688,6 +688,7 @@ module.exports = (swagger, v2) ->
path: '/challenges/{cid}'
description: 'Get a challenge'
parameters: [path('cid','Challenge id','string')]
middleware: [auth.auth, i18n.getUserLanguage]
action: challenges.get
"/challenges/{cid}/csv":