mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Groups can prevent members from getting gems (#8870)
* add possibility for group to block members from getting gems * fixes * fix tests * adds some tests * unit tests * finish unit tests * remove old code
This commit is contained in:
committed by
Sabe Jones
parent
fe9521a63f
commit
78ba596504
@@ -283,7 +283,15 @@ schema.methods.closeChal = async function closeChal (broken = {}) {
|
||||
// Award prize to winner and notify
|
||||
if (winner) {
|
||||
winner.achievements.challenges.push(challenge.name);
|
||||
winner.balance += challenge.prize / 4;
|
||||
|
||||
// If the winner cannot get gems (because of a group policy)
|
||||
// reimburse the leader
|
||||
const winnerCanGetGems = await winner.canGetGems();
|
||||
if (!winnerCanGetGems) {
|
||||
await User.update({_id: challenge.leader}, {$inc: {balance: challenge.prize / 4}}).exec();
|
||||
} else {
|
||||
winner.balance += challenge.prize / 4;
|
||||
}
|
||||
|
||||
winner.addNotification('WON_CHALLENGE');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user