Fix level up webhook (#10347)

* use user._tmp for level up webhook

* use post save hook to send webhook
This commit is contained in:
Matteo Pagliazzi
2018-05-09 19:04:29 +02:00
committed by GitHub
parent bbbd1f9f73
commit a8655d923a
4 changed files with 83 additions and 58 deletions

View File

@@ -20,7 +20,7 @@ module.exports = function updateStats (user, stats, req = {}, analytics) {
if (stats.exp >= experienceToNextLevel) {
user.stats.exp = stats.exp;
// const initialLvl = user.stats.lvl;
const initialLvl = user.stats.lvl;
while (stats.exp >= experienceToNextLevel) {
stats.exp -= experienceToNextLevel;
@@ -50,13 +50,12 @@ module.exports = function updateStats (user, stats, req = {}, analytics) {
}
}
// @TODO: Tmp disable to see if this is causing concurrency
// const newLvl = user.stats.lvl;
//
// if (user.addNotification) user.addNotification('LEVELED_UP', {
// initialLvl,
// newLvl,
// });
const newLvl = user.stats.lvl;
if (!user._tmp.leveledUp) user._tmp.leveledUp = [];
user._tmp.leveledUp.push({
initialLvl,
newLvl,
});
}
user.stats.exp = stats.exp;