diff --git a/website/common/locales/en/npc.json b/website/common/locales/en/npc.json index cb3b592209..01a33788e3 100644 --- a/website/common/locales/en/npc.json +++ b/website/common/locales/en/npc.json @@ -68,6 +68,7 @@ "wishlist": "Wishlist", "items": "Items", "wrongItemType": "The item type \"<%= type %>\" is not valid.", + "wrongItemPath": "The item path \"<%= path %>\" is not valid.", "unpinnedItem": "You unpinned <%= item %>! It will no longer display in your Rewards column.", "cannotUnpinArmoirPotion": "The Health Potion and Enchanted Armoire cannot be unpinned.", "purchasedItem": "You bought <%= itemName %>", diff --git a/website/common/script/ops/pinnedGearUtils.js b/website/common/script/ops/pinnedGearUtils.js index e685b8d93b..2725b2ed69 100644 --- a/website/common/script/ops/pinnedGearUtils.js +++ b/website/common/script/ops/pinnedGearUtils.js @@ -122,11 +122,24 @@ function removePinnedItemsByOwnedGear (user) { function togglePinnedItem (user, {item, type, path}, req = {}) { let arrayToChange; - if (!path) { // If path isn't passed it means an item was passed + if (!path) { + // If path isn't passed it means an item was passed path = getItemInfo(user, type, item, req.language).path; + } else { + if (!item) { + item = get(content, path); + } + + if (!item) { + // path not exists in our content structure + + throw new BadRequest(i18n.t('wrongItemPath', {path}, req.language)); + } + + // check if item exists & valid to be pinned + getItemInfo(user, type, item, req.language); } - if (!item) item = get(content, path); if (path === 'armoire' || path === 'potion') { throw new BadRequest(i18n.t('cannotUnpinArmoirPotion', req.language));