mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
[#1751] /challenges/:cid/:mid task filtering by "in this challenge" at
application level, not Mongo. $elemMatch doesn't support returning multiple items, see http://goo.gl/MxmWdQ & http://goo.gl/Iku44w
This commit is contained in:
@@ -67,12 +67,18 @@ api.get = function(req, res) {
|
||||
|
||||
api.getMember = function(req, res) {
|
||||
var cid = req.params.cid, uid = req.params.uid;
|
||||
var elMatch = {$elemMatch:{'challenge.id':cid}};
|
||||
// TMK we can't use $elemMatch (which would make things much cleaner) @see http://goo.gl/MxmWdQ & http://goo.gl/Iku44w
|
||||
// Revert back to 9fbb45c to see the $elemMatch solution
|
||||
User.findById(uid)
|
||||
.select({'profile.name':1, habits:elMatch, dailys:elMatch, rewards:elMatch, todos:elMatch})
|
||||
.select('profile.name habits dailys rewards todos')
|
||||
.exec(function(err, member){
|
||||
if(err) return res.json(500, {err:err});
|
||||
if (!member) return res.json(404, {err: 'Member '+uid+' for challenge '+cid+' not found'});
|
||||
_.each(['habits','dailys','todos', 'rewards'], function(type){
|
||||
member[type] = _.filter(member[type], function(task){
|
||||
return task.challenge && task.challenge.id && task.challenge.id == cid;
|
||||
});
|
||||
});
|
||||
res.json(member);
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user