mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Added _isMember to APIv2 challenges/:cid endpoint (requires user auth)
This commit is contained in:
@@ -56,6 +56,7 @@ api.list = function(req, res, next) {
|
|||||||
|
|
||||||
// GET
|
// GET
|
||||||
api.get = function(req, res, next) {
|
api.get = function(req, res, next) {
|
||||||
|
var user = res.locals.user;
|
||||||
// TODO use mapReduce() or aggregate() here to
|
// TODO use mapReduce() or aggregate() here to
|
||||||
// 1) Find the sum of users.tasks.values within the challnege (eg, {'profile.name':'tyler', 'sum': 100})
|
// 1) Find the sum of users.tasks.values within the challnege (eg, {'profile.name':'tyler', 'sum': 100})
|
||||||
// 2) Sort by the sum
|
// 2) Sort by the sum
|
||||||
@@ -65,8 +66,11 @@ api.get = function(req, res, next) {
|
|||||||
.exec(function(err, challenge){
|
.exec(function(err, challenge){
|
||||||
if(err) return next(err);
|
if(err) return next(err);
|
||||||
if (!challenge) return res.json(404, {err: 'Challenge ' + req.params.cid + ' not found'});
|
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);
|
res.json(challenge);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
api.csv = function(req, res, next) {
|
api.csv = function(req, res, next) {
|
||||||
|
|||||||
@@ -688,6 +688,7 @@ module.exports = (swagger, v2) ->
|
|||||||
path: '/challenges/{cid}'
|
path: '/challenges/{cid}'
|
||||||
description: 'Get a challenge'
|
description: 'Get a challenge'
|
||||||
parameters: [path('cid','Challenge id','string')]
|
parameters: [path('cid','Challenge id','string')]
|
||||||
|
middleware: [auth.auth, i18n.getUserLanguage]
|
||||||
action: challenges.get
|
action: challenges.get
|
||||||
|
|
||||||
"/challenges/{cid}/csv":
|
"/challenges/{cid}/csv":
|
||||||
|
|||||||
Reference in New Issue
Block a user