From b62f08d5000ddeb8d604e2b0c0fc59d9aba1347a Mon Sep 17 00:00:00 2001 From: Esben Sparre Andreasen Date: Tue, 28 Nov 2017 02:51:25 +0100 Subject: [PATCH] Misc. bug fixes from lgtm.com (2) (#9474) * Remove dead branch of ternary: `gift` is always truthy here Problem found here: - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/server/libs/amazonPayments.js?sort=name&dir=ASC&mode=heatmap&excluded=false#x5a22f31110a55091:1 * Remove superfluous argument, preenUserHistory only takes two args Problem found here: - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/server/libs/cron.js?sort=name&dir=ASC&mode=heatmap&excluded=false#xf16a045ecabb07f6:1 * Cleanup: remove useless assignments Problems found here: - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/client/store/actions/shops.js?sort=name&dir=ASC&mode=heatmap&excluded=false#xf782ed2cf920441%3A1 - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/client/app.vue?sort=name&dir=ASC&mode=heatmap&excluded=false#x172c1dda85e84dc8%3A1 - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/client/components/settings/site.vue#x9b3afee802a3a8f8%3A1 - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/client/components/selectMembersModal.vue?sort=name&dir=ASC&mode=heatmap&excluded=false#x1fbc2a3d62facd70:1 - https://lgtm.com/projects/g/HabitRPG/habitrpg/snapshot/dist-98076885-1510577633582/files/website/common/script/libs/taskClasses.js?sort=name&dir=ASC&mode=heatmap&excluded=false#x41ce0e121a4defee:1 * Fix online editor whitespace change. --- website/client/app.vue | 3 +-- website/client/components/selectMembersModal.vue | 2 +- website/client/components/settings/site.vue | 1 - website/client/store/actions/shops.js | 8 ++++++++ website/common/script/libs/taskClasses.js | 3 +-- website/server/libs/amazonPayments.js | 2 +- website/server/libs/cron.js | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/website/client/app.vue b/website/client/app.vue index abe3c6c3b5..192fdb6571 100644 --- a/website/client/app.vue +++ b/website/client/app.vue @@ -296,7 +296,6 @@ export default { const modalId = bvEvent.target.id; let modalStackLength = this.$store.state.modalStack.length; - let modalOnTop = this.$store.state.modalStack[modalStackLength - 1]; let modalSecondToTop = this.$store.state.modalStack[modalStackLength - 2]; // Don't remove modal if hid was called from main app // @TODO: I'd reather use this, but I don't know how to pass data to hidden event @@ -308,7 +307,7 @@ export default { // Recalculate and show the last modal if there is one modalStackLength = this.$store.state.modalStack.length; - modalOnTop = this.$store.state.modalStack[modalStackLength - 1]; + let modalOnTop = this.$store.state.modalStack[modalStackLength - 1]; if (modalOnTop) this.$root.$emit('bv::show::modal', modalOnTop, {fromRoot: true}); }); }, diff --git a/website/client/components/selectMembersModal.vue b/website/client/components/selectMembersModal.vue index 063abb9170..ba333335f9 100644 --- a/website/client/components/selectMembersModal.vue +++ b/website/client/components/selectMembersModal.vue @@ -133,7 +133,7 @@ export default { let sortedMembers = this.members; if (!this.sortOption) return sortedMembers; - sortedMembers = sortBy(this.members, [(member) => { + sortBy(this.members, [(member) => { if (this.sortOption === 'tier') { if (!member.contributor) return; return member.contributor.level; diff --git a/website/client/components/settings/site.vue b/website/client/components/settings/site.vue index e581c591a1..eb8132a973 100644 --- a/website/client/components/settings/site.vue +++ b/website/client/components/settings/site.vue @@ -341,7 +341,6 @@ export default { await axios.put(`/api/v3/user/auth/update-${attribute}`, updates); alert(this.$t(`${attribute}Success`)); this.user[attribute] = updates[attribute]; - updates = {}; }, openRestoreModal () { this.$root.$emit('bv::show::modal', 'restore'); diff --git a/website/client/store/actions/shops.js b/website/client/store/actions/shops.js index 5efe395f74..97d3dfc619 100644 --- a/website/client/store/actions/shops.js +++ b/website/client/store/actions/shops.js @@ -41,6 +41,14 @@ async function buyArmoire (store, params) { const quantity = params.quantity || 1; let armoire = content.armoire; + buyOp(store.state.user.data, { + params: { + key: 'armoire', + }, + type: 'armoire', + quantity, + }); + // We need the server result because Armoire has random item in the result let result = await axios.post('/api/v3/user/buy/armoire', { type: 'armoire', diff --git a/website/common/script/libs/taskClasses.js b/website/common/script/libs/taskClasses.js index 83df0470e7..a61a82dd75 100644 --- a/website/common/script/libs/taskClasses.js +++ b/website/common/script/libs/taskClasses.js @@ -14,7 +14,6 @@ module.exports = function taskClasses (task, filters = [], dayStart = 0, lastCro return ''; } let type = task.type; - let classes = task.type; let completed = task.completed; let value = task.value; let priority = task.priority; @@ -29,7 +28,7 @@ module.exports = function taskClasses (task, filters = [], dayStart = 0, lastCro } } - classes = task.type; + let classes = task.type; if (task._editing) { classes += ' beingEdited'; } diff --git a/website/server/libs/amazonPayments.js b/website/server/libs/amazonPayments.js index 49b4045b75..f71185526f 100644 --- a/website/server/libs/amazonPayments.js +++ b/website/server/libs/amazonPayments.js @@ -157,7 +157,7 @@ api.checkout = async function checkout (options = {}) { if (gift) { if (gift.type === this.constants.GIFT_TYPE_SUBSCRIPTION) method = this.constants.METHOD_CREATE_SUBSCRIPTION; - gift.member = await User.findById(gift ? gift.uuid : undefined).exec(); + gift.member = await User.findById(gift.uuid).exec(); data.gift = gift; data.paymentMethod = this.constants.PAYMENT_METHOD_GIFT; } diff --git a/website/server/libs/cron.js b/website/server/libs/cron.js index 861d1fa6ef..cf4ff14635 100644 --- a/website/server/libs/cron.js +++ b/website/server/libs/cron.js @@ -413,7 +413,7 @@ export function cron (options = {}) { // preen user history so that it doesn't become a performance problem // also for subscribed users but differently // TODO also do while resting in the inn. Note that later we'll be allowing the value/color of tasks to change while sleeping (https://github.com/HabitRPG/habitica/issues/5232), so the code in performSleepTasks() might be best merged back into here for that. Perhaps wait until then to do preen history for sleeping users. - preenUserHistory(user, tasksByType, user.preferences.timezoneOffset); + preenUserHistory(user, tasksByType); if (perfect && atLeastOneDailyDue) { user.achievements.perfect++;