pinned items fixes #10012 (#10216)

* Don't unpin non-gear items

Assumes that multiple of bundles, quests, eggs, potions can be bought

* Added tests

* Changed type checking and made variables global

* Lint fix
This commit is contained in:
Tyler Nychka
2018-04-13 09:19:44 -04:00
committed by Matteo Pagliazzi
parent c12ae9ea25
commit 5449652bd2
2 changed files with 22 additions and 4 deletions
+7 -4
View File
@@ -106,6 +106,8 @@ function purchaseItem (user, item, price, type, key) {
}
}
const acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'quests', 'gear', 'bundles'];
const singlePurchaseTypes = ['gear'];
module.exports = function purchase (user, req = {}, analytics) {
let type = get(req.params, 'type');
let key = get(req.params, 'key');
@@ -129,8 +131,7 @@ module.exports = function purchase (user, req = {}, analytics) {
return gemResponse;
}
let acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'quests', 'gear', 'bundles'];
if (acceptedTypes.indexOf(type) === -1) {
if (!acceptedTypes.includes(type)) {
throw new NotFound(i18n.t('notAccteptedType', req.language));
}
@@ -144,8 +145,10 @@ module.exports = function purchase (user, req = {}, analytics) {
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
}
let itemInfo = getItemInfo(user, type, item);
removeItemByPath(user, itemInfo.path);
if (singlePurchaseTypes.includes(type)) {
let itemInfo = getItemInfo(user, type, item);
removeItemByPath(user, itemInfo.path);
}
for (let i = 0; i < quantity; i += 1) {
purchaseItem(user, item, price, type, key);