mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
bug fix to challenge.tasks._id out of sync
This commit is contained in:
@@ -248,10 +248,11 @@ UserSchema.pre('save', function(next) {
|
|||||||
UserSchema.methods.syncScoreToChallenge = function(task, delta){
|
UserSchema.methods.syncScoreToChallenge = function(task, delta){
|
||||||
if (!task.challenge || !task.challenge.id || task.challenge.broken) return;
|
if (!task.challenge || !task.challenge.id || task.challenge.broken) return;
|
||||||
if (task.type == 'reward') return; // we don't want to update the reward GP cost
|
if (task.type == 'reward') return; // we don't want to update the reward GP cost
|
||||||
|
var self = this;
|
||||||
Challenge.findById(task.challenge.id, function(err, chal){
|
Challenge.findById(task.challenge.id, function(err, chal){
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
var t = chal.tasks[task.id];
|
var t = chal.tasks[task.id];
|
||||||
if (!t) return Challenge.syncToUser(this); // this task was removed from the challenge, notify user
|
if (!t) return chal.syncToUser(self); // this task was removed from the challenge, notify user
|
||||||
t.value += delta;
|
t.value += delta;
|
||||||
t.history.push({value: t.value, date: +new Date});
|
t.history.push({value: t.value, date: +new Date});
|
||||||
chal.save();
|
chal.save();
|
||||||
|
|||||||
Reference in New Issue
Block a user