mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
commit
2b08e550e0
5 changed files with 8 additions and 21 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'};
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ var User = require('./../models/user').model;
|
|||
var ga = require('./../utils').ga;
|
||||
var Group = require('./../models/group').model;
|
||||
var Challenge = require('./../models/challenge').model;
|
||||
var moment = require('moment');
|
||||
var logging = require('./../logging');
|
||||
var acceptablePUTPaths;
|
||||
var api = module.exports;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ var HabitSchema = new Schema(
|
|||
up: {type: Boolean, 'default': true},
|
||||
down: {type: Boolean, 'default': true}
|
||||
}, TaskSchema)
|
||||
, { _id: false }
|
||||
, { _id: false, minimize:false }
|
||||
);
|
||||
|
||||
var collapseChecklist = {type:Boolean, 'default':false};
|
||||
|
|
@ -66,7 +66,7 @@ var DailySchema = new Schema(
|
|||
checklist:checklist,
|
||||
streak: {type: Number, 'default': 0}
|
||||
}, TaskSchema)
|
||||
, { _id: false }
|
||||
, { _id: false, minimize:false }
|
||||
)
|
||||
|
||||
var TodoSchema = new Schema(
|
||||
|
|
@ -78,14 +78,14 @@ var TodoSchema = new Schema(
|
|||
collapseChecklist:collapseChecklist,
|
||||
checklist:checklist
|
||||
}, TaskSchema)
|
||||
, { _id: false }
|
||||
, { _id: false, minimize:false }
|
||||
);
|
||||
|
||||
var RewardSchema = new Schema(
|
||||
_.defaults({
|
||||
type: {type:String, 'default': 'reward'}
|
||||
}, TaskSchema)
|
||||
, { _id: false }
|
||||
, { _id: false, minimize:false }
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ async = require("async")
|
|||
diff = require("deep-diff")
|
||||
superagentDefaults = require("superagent-defaults")
|
||||
request = superagentDefaults()
|
||||
moment = require("moment")
|
||||
conf = require("nconf")
|
||||
conf.argv().env().file(file: __dirname + "../config.json").defaults()
|
||||
conf.set "port", "1337"
|
||||
|
|
|
|||
Loading…
Reference in a new issue