mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
challenge prize: award winner 1 achievement and challenge.prize gems. then close challenge.
This commit is contained in:
@@ -108,7 +108,7 @@ habitrpg.controller("ChallengesCtrl", ['$scope', 'User', 'Challenges', 'Notifica
|
|||||||
};
|
};
|
||||||
$scope.selectWinner = function(challenge) {
|
$scope.selectWinner = function(challenge) {
|
||||||
if (!confirm("Are you sure?")) return;
|
if (!confirm("Are you sure?")) return;
|
||||||
challenge.$selectWinner({uid:challenge.winner}, function(){
|
challenge.$close({uid:challenge.winner}, function(){
|
||||||
$scope.popoverEl.popover('destroy');
|
$scope.popoverEl.popover('destroy');
|
||||||
backToChallenges();
|
backToChallenges();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ angular.module('challengeServices', ['ngResource']).
|
|||||||
{
|
{
|
||||||
//'query': {method: "GET", isArray:false}
|
//'query': {method: "GET", isArray:false}
|
||||||
join: {method: "POST", url: API_URL + '/api/v1/challenges/:cid/join'},
|
join: {method: "POST", url: API_URL + '/api/v1/challenges/:cid/join'},
|
||||||
leave: {method: "POST", url: API_URL + '/api/v1/challenges/:cid/leave'}
|
leave: {method: "POST", url: API_URL + '/api/v1/challenges/:cid/leave'},
|
||||||
|
close: {method: "POST", params: {uid:''}, url: API_URL + '/api/v1/challenges/:cid/close'}
|
||||||
});
|
});
|
||||||
|
|
||||||
//var challenges = [];
|
//var challenges = [];
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ function closeChal(cid, broken, cb) {
|
|||||||
_.each(users, function(user){
|
_.each(users, function(user){
|
||||||
_.each(user.tasks, function(task){
|
_.each(user.tasks, function(task){
|
||||||
if (task.challenge && task.challenge.id == removed._id) {
|
if (task.challenge && task.challenge.id == removed._id) {
|
||||||
_.mege(task.challenge, broken);
|
_.merge(task.challenge, broken);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
parallel.push(function(cb3){
|
parallel.push(function(cb3){
|
||||||
@@ -240,7 +240,9 @@ function closeChal(cid, broken, cb) {
|
|||||||
], cb);
|
], cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE
|
/**
|
||||||
|
* Delete & close
|
||||||
|
*/
|
||||||
api['delete'] = function(req, res){
|
api['delete'] = function(req, res){
|
||||||
closeChal(req.params.cid, {broken: 'CHALLENGE_DELETED'}, function(err){
|
closeChal(req.params.cid, {broken: 'CHALLENGE_DELETED'}, function(err){
|
||||||
if (err) return res.json(500, {err: err});
|
if (err) return res.json(500, {err: err});
|
||||||
@@ -248,6 +250,9 @@ api['delete'] = function(req, res){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Winner & Close
|
||||||
|
*/
|
||||||
api.selectWinner = function(req, res) {
|
api.selectWinner = function(req, res) {
|
||||||
if (!req.query.uid) return res.json(401, {err: 'Must select a winner'});
|
if (!req.query.uid) return res.json(401, {err: 'Must select a winner'});
|
||||||
var chal;
|
var chal;
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ router.post('/challenges', auth.auth, challenges.create)
|
|||||||
router.get('/challenges/:cid', auth.auth, challenges.get)
|
router.get('/challenges/:cid', auth.auth, challenges.get)
|
||||||
router.post('/challenges/:cid', auth.auth, challenges.update)
|
router.post('/challenges/:cid', auth.auth, challenges.update)
|
||||||
router['delete']('/challenges/:cid', auth.auth, challenges['delete'])
|
router['delete']('/challenges/:cid', auth.auth, challenges['delete'])
|
||||||
|
router.post('/challenges/:cid/close', auth.auth, challenges.selectWinner)
|
||||||
router.post('/challenges/:cid/join', auth.auth, challenges.join)
|
router.post('/challenges/:cid/join', auth.auth, challenges.join)
|
||||||
router.post('/challenges/:cid/leave', auth.auth, challenges.leave)
|
router.post('/challenges/:cid/leave', auth.auth, challenges.leave)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user