diff --git a/website/src/controllers/api-v3/challenges.js b/website/src/controllers/api-v3/challenges.js index fa3a71b818..252ffe6c7e 100644 --- a/website/src/controllers/api-v3/challenges.js +++ b/website/src/controllers/api-v3/challenges.js @@ -30,12 +30,12 @@ api.createChallenge = { async handler (req, res) { let user = res.locals.user; - req.checkBody('group', res.t('groupIdRequired')).notEmpty(); + req.checkBody('groupId', res.t('groupIdRequired')).notEmpty(); let validationErrors = req.validationErrors(); if (validationErrors) throw validationErrors; - let groupId = req.body.group; + let groupId = req.body.groupId; let prize = req.body.prize; let group = await Group.getGroup(user, groupId, '-chat'); @@ -107,7 +107,7 @@ api.getChallenges = { let challenges = await Challenge.find({ $or: [ {_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 ], _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(), // 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 - 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()); } diff --git a/website/src/models/challenge.js b/website/src/models/challenge.js index d5b3bf1a1b..00ab26a491 100644 --- a/website/src/models/challenge.js +++ b/website/src/models/challenge.js @@ -11,7 +11,7 @@ let schema = new Schema({ name: {type: String, required: true}, shortName: {type: String, required: true}, // TODO what is it? description: String, - official: {type: Boolean, default: false}, + official: {type: Boolean, default: false}, // TODO only settable by admin tasksOrder: { habits: [{type: String, ref: 'Task'}], dailys: [{type: String, ref: 'Task'}], @@ -19,14 +19,15 @@ let schema = new Schema({ rewards: [{type: String, ref: 'Task'}], }, leader: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.'], required: true}, - group: {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? + 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? not settable? 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, { - noSet: ['_id', 'memberCount', 'tasksOrder'], + noSet: ['_id', 'memberCount', 'challengeCount', 'tasksOrder'], });