mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-05-21 21:28:42 +00:00
fix(challenges): since we're setting {minimize:false} on tasks, don't
overwrite user tasks.*.challenges in the _.merge()
This commit is contained in:
parent
704a8658f3
commit
0bb1de680c
2 changed files with 2 additions and 17 deletions
|
|
@ -115,22 +115,7 @@ api.getMember = function(req, res, next) {
|
|||
var uid = req.params.uid;
|
||||
|
||||
// We need to start using the aggregation framework instead of in-app filtering, see http://docs.mongodb.org/manual/aggregation/
|
||||
|
||||
// See http://stackoverflow.com/a/18546277/362790
|
||||
// However, this doesn't work. If not all $match conditions are met (eg, if a challenge doesn't have any one of habit/daily/todo/reward
|
||||
// then the $match fails and that user object is removed from the results. See http://stackoverflow.com/questions/23636175/filter-subdocument-array-while-still-returning-parent-data-if-empty
|
||||
// User.aggregate()
|
||||
// .match({_id: uid})
|
||||
// .unwind('habits').match({'habits.challenge.id': cid})
|
||||
// .unwind('dailys').match({'dailys.challenge.id': cid})
|
||||
// .unwind('todos').match({'todos.challenge.id': cid})
|
||||
// .unwind('rewards').match({'rewards.challenge.id': cid})
|
||||
// .group({_id:'$_id', 'profile.name':'$profile.name', habits:{$push: '$habits'}, dailys:{$push:'$dailys'}, todos:{$push:'$todos'}, rewards:{$push:'$rewards'}})
|
||||
// .exec(function(err, member){
|
||||
// if (err) return next(err);
|
||||
// if (!member) return res.json(404, {err: 'Member '+uid+' for challenge '+cid+' not found'});
|
||||
// res.json(member[0]);
|
||||
// });
|
||||
// See code at 32c0e75 for unwind/group example
|
||||
|
||||
//http://stackoverflow.com/questions/24027213/how-to-match-multiple-array-elements-without-using-unwind
|
||||
var proj = {'profile.name':'$profile.name'};
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ ChallengeSchema.methods.toJSON = function(){
|
|||
function syncableAttrs(task) {
|
||||
var t = (task.toObject) ? task.toObject() : task; // lodash doesn't seem to like _.omit on EmbeddedDocument
|
||||
// only sync/compare important attrs
|
||||
var omitAttrs = 'history tags completed streak notes'.split(' ');
|
||||
var omitAttrs = 'challenge history tags completed streak notes'.split(' ');
|
||||
if (t.type != 'reward') omitAttrs.push('value');
|
||||
return _.omit(t, omitAttrs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue