challenges: add group.memberCount and ability to specifiy field projections in GET request /api/v1/groups?type=guild&fields=name,description,chat

This commit is contained in:
Tyler Renelle
2013-10-28 17:31:27 -07:00
parent 4ac0ef4ac2
commit c5671550f1
6 changed files with 71 additions and 45 deletions
+4
View File
@@ -26,6 +26,8 @@ var GroupSchema = new Schema({
# }]
*/
memberCount: {type: Number, 'default': 0},
challengeCount: {type: Number, 'default': 0},
balance: Number,
logo: String,
leaderMessage: String,
@@ -59,6 +61,8 @@ function removeDuplicates(doc){
GroupSchema.pre('save', function(next){
removeDuplicates(this);
this.memberCount = _.size(this.members);
this.challengeCount = _.size(this.challenges);
next();
})