mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
* Fix: moved debuffPotions from vue component - Move logic of choosing proper debuf potion from vue component to website commons - introduce new function to get debuffSpellItems * Fix: move debuffPotions to server * Refactoring: move setting of debuff potion to func * Fix: sanity * Refactoring & Tests: - Create test case for get and set DebuffPotionItems functions - Fix setDebuffPotionItems function to not create duplicated debuff items - Make debuff potion type of items unpinnable - Move list of debuffs to constant to reuse it in tests and functions * Fix: typo in test describe * Fix: translation of unpin * Fix: setDebuffPotionItems on cron buffs reset * Fix: use full path for debuff potions
31 lines
748 B
JavaScript
31 lines
748 B
JavaScript
import getDebuffPotionItems from './getDebuffPotionItems';
|
|
|
|
|
|
module.exports = function setDebuffPotionItems (user) {
|
|
const debuffPotionItems = getDebuffPotionItems(user);
|
|
|
|
if (debuffPotionItems.length) {
|
|
let isPresent = false;
|
|
const isUserHaveDebuffInPinnedItems = user.pinnedItems.find(pinnedItem => {
|
|
debuffPotionItems.forEach(debuffPotion => {
|
|
if (!isPresent) {
|
|
isPresent = debuffPotion.path === pinnedItem.path;
|
|
}
|
|
});
|
|
return isPresent;
|
|
});
|
|
|
|
if (!isUserHaveDebuffInPinnedItems) {
|
|
user.pinnedItems.push(...debuffPotionItems);
|
|
}
|
|
} else {
|
|
user.pinnedItems = user.pinnedItems.filter(item => {
|
|
return item.type !== 'debuffPotion';
|
|
});
|
|
}
|
|
|
|
return user;
|
|
};
|
|
|
|
|