mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
[#1675] fixes to populating Group.challenges, and display challenges in party
page. I'm not sure about having challenges as a subdoc anymore, i think it will be better performance and maintenance if we just reference Challenge.group/members and remove User.challenges & Group.challenges
This commit is contained in:
@@ -156,7 +156,7 @@ api.create = function(req, res){
|
|||||||
var challenge = new Challenge(req.body); // FIXME sanitize
|
var challenge = new Challenge(req.body); // FIXME sanitize
|
||||||
challenge.save(function(err, saved){
|
challenge.save(function(err, saved){
|
||||||
if (err) return res.json(500, {err:err});
|
if (err) return res.json(500, {err:err});
|
||||||
Group.findByIdAndUpdate(saved.group, {$addToSet:{challenges:saved._id}}) // fixme error-check, and also better to do in middleware?
|
Group.update({_id:saved.group}, {$addToSet:{challenges:saved._id}}) // fixme error-check, and also better to do in middleware?
|
||||||
res.json(saved);
|
res.json(saved);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ var api = module.exports;
|
|||||||
var itemFields = 'items.armor items.head items.shield items.weapon items.currentPet';
|
var itemFields = 'items.armor items.head items.shield items.weapon items.currentPet';
|
||||||
var partyFields = 'profile preferences stats achievements party backer flags.rest auth.timestamps ' + itemFields;
|
var partyFields = 'profile preferences stats achievements party backer flags.rest auth.timestamps ' + itemFields;
|
||||||
var nameFields = 'profile.name';
|
var nameFields = 'profile.name';
|
||||||
|
var challengeFields = '_id name';
|
||||||
|
|
||||||
api.getMember = function(req, res) {
|
api.getMember = function(req, res) {
|
||||||
User.findById(req.params.uid).select(partyFields).exec(function(err, user){
|
User.findById(req.params.uid).select(partyFields).exec(function(err, user){
|
||||||
@@ -106,18 +107,25 @@ api.get = function(req, res) {
|
|||||||
// This will be called for the header, we need extra members' details than usuals
|
// This will be called for the header, we need extra members' details than usuals
|
||||||
if (gid == 'party') {
|
if (gid == 'party') {
|
||||||
Group.findOne({type: 'party', members: {'$in': [user._id]}})
|
Group.findOne({type: 'party', members: {'$in': [user._id]}})
|
||||||
.populate('members invites', partyFields).exec(function(err, group){
|
.populate('members', partyFields)
|
||||||
|
.populate('invites', nameFields)
|
||||||
|
.populate('challenges', challengeFields)
|
||||||
|
.exec(function(err, group){
|
||||||
if (err) return res.json(500,{err:err});
|
if (err) return res.json(500,{err:err});
|
||||||
res.json(group);
|
res.json(group);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Group.findById(gid).populate('members invites', nameFields).exec(function(err, group){
|
Group.findById(gid)
|
||||||
if ( (group.type == 'guild' && group.privacy == 'private') || group.type == 'party') {
|
.populate('members', partyFields)
|
||||||
if(!_.find(group.members, {_id: user._id}))
|
.populate('invites', nameFields)
|
||||||
return res.json(401, {err: "You don't have access to this group"});
|
.populate('challenges', challengeFields)
|
||||||
}
|
.exec(function(err, group){
|
||||||
res.json(group);
|
if ( (group.type == 'guild' && group.privacy == 'private') || group.type == 'party') {
|
||||||
})
|
if(!_.find(group.members, {_id: user._id}))
|
||||||
|
return res.json(401, {err: "You don't have access to this group"});
|
||||||
|
}
|
||||||
|
res.json(group);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ var GroupSchema = new Schema({
|
|||||||
balance: Number,
|
balance: Number,
|
||||||
logo: String,
|
logo: String,
|
||||||
leaderMessage: String,
|
leaderMessage: String,
|
||||||
challenges: [{type:'String', ref:'Challenge'}]
|
challenges: [{type:'String', ref:'Challenge'}] // do we need this? could depend on back-ref instead (Challenge.find({group:GID}))
|
||||||
}, {
|
}, {
|
||||||
strict: 'throw',
|
strict: 'throw',
|
||||||
minimize: false // So empty objects are returned
|
minimize: false // So empty objects are returned
|
||||||
|
|||||||
@@ -84,17 +84,19 @@ a.pull-right.gem-wallet(popover-trigger='mouseenter', popover-title='Guild Bank'
|
|||||||
|
|
||||||
.modal(style='position: relative;top: auto;left: auto;right: auto;margin: 0 auto 20px;z-index: 1;max-width: 100%;')
|
.modal(style='position: relative;top: auto;left: auto;right: auto;margin: 0 auto 20px;z-index: 1;max-width: 100%;')
|
||||||
.modal-header
|
.modal-header
|
||||||
h3 Challenges
|
h3
|
||||||
|
| Challenges
|
||||||
|
a.pull-right(target='_blank', href='https://trello.com/card/challenges-individual-party-guild-public/50e5d3684fe3a7266b0036d6/58')
|
||||||
|
i.icon-question-sign
|
||||||
.modal-body
|
.modal-body
|
||||||
a(target='_blank', href='https://trello.com/card/challenges-individual-party-guild-public/50e5d3684fe3a7266b0036d6/58') Details
|
div(ng-if='group.challenges')
|
||||||
div(ng-show='group.challenges')
|
|
||||||
table.table.table-striped
|
table.table.table-striped
|
||||||
tr(ng-repeat='challenge in group.challenges')
|
tr(ng-repeat='challenge in group.challenges')
|
||||||
td
|
td
|
||||||
| {{challenge.name}}
|
a(ui-sref='options.social.challenges.detail({cid:challenge._id})') {{challenge.name}}
|
||||||
p.
|
p.
|
||||||
Visit the <span class=label><i class=icon-bullhorn></i> Challenges</span> for more information.
|
Visit the <span class=label><i class=icon-bullhorn></i> Challenges</span> for more information.
|
||||||
div(ng-hid='group.challenges')
|
div(ng-if='!group.challenges')
|
||||||
p.
|
p.
|
||||||
No challenges yet, visit the <span class=label><i class=icon-bullhorn></i> Challenges</span> tab to create one.
|
No challenges yet, visit the <span class=label><i class=icon-bullhorn></i> Challenges</span> tab to create one.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user