[#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:
Tyler Renelle
2013-11-10 23:41:42 -08:00
parent 9fbb45c253
commit 72f64fa85c
3 changed files with 15 additions and 9 deletions

View File

@@ -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);
})
}

View File

@@ -9,12 +9,12 @@ script(type='text/ng-template', id='partials/options.social.challenges.detail.cl
script(type='text/ng-template', id='partials/options.social.challenges.detail.member.html')
.modal.wide-modal
.modal-header
button.close(type='button', ng-click='$state.go("^")', aria-hidden='true') ×
h3 {{obj.profile.name}}
.modal-body
habitrpg-tasks(main=false)
.modal-footer
a.btn(ng-click='$state.go("^")') Close
button.close(type='button', ng-click='$state.go("^")', aria-hidden='true') ×
h3 {{obj.profile.name}}
.modal-body
habitrpg-tasks(main=false)
.modal-footer
a.btn(ng-click='$state.go("^")') Close
script(type='text/ng-template', id='partials/options.social.challenges.detail.html')
// Edit button

View File

@@ -1,4 +1,4 @@
// @TODO ui:connectionAlert
//.header-wrap(ng-controller='HeaderCtrl', data-spy="affix", data-offset-top="148")
.header-wrap(ng-controller='HeaderCtrl')
a.label.undo-button(x-bind='click:undo', ng-show='_undo') Undo
div(ng-if='!user.preferences.hideHeader')