fix(stats): enforce sensible maxima in db

This commit is contained in:
Sabe Jones
2023-10-17 22:31:43 +00:00
parent 832acb1617
commit 4974712d6c
4 changed files with 26 additions and 5 deletions

View File

@@ -148,7 +148,7 @@ import svgGold from '@/assets/svg/gold.svg';
import level from '@/assets/svg/level.svg';
import streakIcon from '@/assets/svg/streak.svg';
import { mapState } from '@/libs/store';
import { MAX_LEVEL_HARD_CAP } from '../../../../../common/script/constants';
import { MAX_LEVEL_HARD_CAP, MAX_FIELD_HARD_CAP } from '../../../../../common/script/constants';
export default {
components: { SaveCancelButtons },
@@ -231,10 +231,6 @@ export default {
return;
}
if (this.restoreValues.lvl > MAX_LEVEL_HARD_CAP) {
this.restoreValues.lvl = MAX_LEVEL_HARD_CAP;
}
const userChangedLevel = this.restoreValues.lvl !== this.user.stats.lvl;
const userDidNotChangeExp = this.restoreValues.exp === this.user.stats.exp;
if (userChangedLevel && userDidNotChangeExp) {
@@ -265,6 +261,9 @@ export default {
) {
this.restoreValues[stat] = this.user.stats[stat];
valid = false;
} else if (this.restoreValues[stat] > MAX_FIELD_HARD_CAP) {
this.restoreValues[stat] = MAX_FIELD_HARD_CAP;
valid = false;
}
}
@@ -274,6 +273,9 @@ export default {
|| inputLevel < 1) {
this.restoreValues.lvl = this.user.stats.lvl;
valid = false;
} else if (inputLevel > MAX_LEVEL_HARD_CAP) {
this.restoreValues.lvl = MAX_LEVEL_HARD_CAP;
valid = false;
}
const inputStreak = Number(this.restoreValues.streak);