challenge.group -> challenge.groupId

This commit is contained in:
Matteo Pagliazzi
2016-01-12 19:43:41 +01:00
parent baf0179eb7
commit 45aacc1e6f
2 changed files with 11 additions and 10 deletions

View File

@@ -30,12 +30,12 @@ api.createChallenge = {
async handler (req, res) { async handler (req, res) {
let user = res.locals.user; let user = res.locals.user;
req.checkBody('group', res.t('groupIdRequired')).notEmpty(); req.checkBody('groupId', res.t('groupIdRequired')).notEmpty();
let validationErrors = req.validationErrors(); let validationErrors = req.validationErrors();
if (validationErrors) throw validationErrors; if (validationErrors) throw validationErrors;
let groupId = req.body.group; let groupId = req.body.groupId;
let prize = req.body.prize; let prize = req.body.prize;
let group = await Group.getGroup(user, groupId, '-chat'); let group = await Group.getGroup(user, groupId, '-chat');
@@ -107,7 +107,7 @@ api.getChallenges = {
let challenges = await Challenge.find({ let challenges = await Challenge.find({
$or: [ $or: [
{_id: {$in: user.challenges}}, // Challenges where the user is participating {_id: {$in: user.challenges}}, // Challenges where the user is participating
{group: {$in: groups}}, // Challenges in groups where I'm a member {groupId: {$in: groups}}, // Challenges in groups where I'm a member
{leader: user._id}, // Challenges where I'm the leader {leader: user._id}, // Challenges where I'm the leader
], ],
_id: {$ne: '95533e05-1ff9-4e46-970b-d77219f199e9'}, // remove the Spread the Word Challenge for now, will revisit when we fix the closing-challenge bug TODO revisit _id: {$ne: '95533e05-1ff9-4e46-970b-d77219f199e9'}, // remove the Spread the Word Challenge for now, will revisit when we fix the closing-challenge bug TODO revisit
@@ -183,11 +183,11 @@ function _closeChal (challenge, broken = {}) {
}, },
}, {multi: true}).exec(), }, {multi: true}).exec(),
// Update the challengeCount on the group // Update the challengeCount on the group
Group.update({_id: challenge.group}, {$inc: {challengeCount: -1}}).exec(), Group.update({_id: challenge.groupId}, {$inc: {challengeCount: -1}}).exec(),
]; ];
// Refund the leader if the challenge is closed and the group not the tavern // Refund the leader if the challenge is closed and the group not the tavern
if (challenge.group !== 'habitrpg' && brokenReason === 'CHALLENGE_DELETED') { if (challenge.groupId !== 'habitrpg' && brokenReason === 'CHALLENGE_DELETED') {
tasks.push(User.update({_id: challenge.leader}, {$inc: {balance: challenge.prize / 4}}).exec()); tasks.push(User.update({_id: challenge.leader}, {$inc: {balance: challenge.prize / 4}}).exec());
} }

View File

@@ -11,7 +11,7 @@ let schema = new Schema({
name: {type: String, required: true}, name: {type: String, required: true},
shortName: {type: String, required: true}, // TODO what is it? shortName: {type: String, required: true}, // TODO what is it?
description: String, description: String,
official: {type: Boolean, default: false}, official: {type: Boolean, default: false}, // TODO only settable by admin
tasksOrder: { tasksOrder: {
habits: [{type: String, ref: 'Task'}], habits: [{type: String, ref: 'Task'}],
dailys: [{type: String, ref: 'Task'}], dailys: [{type: String, ref: 'Task'}],
@@ -19,14 +19,15 @@ let schema = new Schema({
rewards: [{type: String, ref: 'Task'}], rewards: [{type: String, ref: 'Task'}],
}, },
leader: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.'], required: true}, leader: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
group: {type: String, ref: 'Group', validate: [validator.isUUID, 'Invalid uuid.'], required: true}, groupId: {type: String, ref: 'Group', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
timestamp: {type: Date, default: Date.now, required: true}, // TODO what is this? use timestamps from plugin? timestamp: {type: Date, default: Date.now, required: true}, // TODO what is this? use timestamps from plugin? not settable?
memberCount: {type: Number, default: 0}, memberCount: {type: Number, default: 0},
prize: {type: Number, default: 0, min: 0}, challengeCount: {type: Number, default: 0},
prize: {type: Number, default: 0, min: 0}, // TODO no update?
}); });
schema.plugin(baseModel, { schema.plugin(baseModel, {
noSet: ['_id', 'memberCount', 'tasksOrder'], noSet: ['_id', 'memberCount', 'challengeCount', 'tasksOrder'],
}); });