Ported release pets, added unit tests, added route with integration tests
This commit is contained in:
@@ -118,6 +118,7 @@ import purchase from './ops/purchase';
|
||||
import purchaseHourglass from './ops/hourglassPurchase';
|
||||
import readCard from './ops/readCard';
|
||||
import openMysteryItem from './ops/openMysteryItem';
|
||||
import releasePets from './ops/releasePets';
|
||||
|
||||
api.ops = {
|
||||
scoreTask,
|
||||
@@ -137,6 +138,7 @@ api.ops = {
|
||||
purchaseHourglass,
|
||||
readCard,
|
||||
openMysteryItem,
|
||||
releasePets,
|
||||
};
|
||||
|
||||
import handleTwoHanded from './fns/handleTwoHanded';
|
||||
|
||||
@@ -1,32 +1,40 @@
|
||||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
|
||||
module.exports = function(user, req, cb, analytics) {
|
||||
var analyticsData, pet;
|
||||
module.exports = function releasePets (user, req = {}, analytics) {
|
||||
if (user.balance < 1) {
|
||||
return typeof cb === "function" ? cb({
|
||||
code: 401,
|
||||
message: i18n.t('notEnoughGems', req.language)
|
||||
}) : void 0;
|
||||
} else {
|
||||
user.balance -= 1;
|
||||
for (pet in content.pets) {
|
||||
user.items.pets[pet] = 0;
|
||||
}
|
||||
if (!user.achievements.beastMasterCount) {
|
||||
user.achievements.beastMasterCount = 0;
|
||||
}
|
||||
user.achievements.beastMasterCount++;
|
||||
user.items.currentPet = "";
|
||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||
}
|
||||
analyticsData = {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior'
|
||||
|
||||
user.balance -= 1;
|
||||
user.items.currentPet = '';
|
||||
|
||||
for (let pet in content.pets) {
|
||||
user.items.pets[pet] = 0;
|
||||
}
|
||||
|
||||
if (!user.achievements.beastMasterCount) {
|
||||
user.achievements.beastMasterCount = 0;
|
||||
}
|
||||
user.achievements.beastMasterCount++;
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('release pets', {
|
||||
uuid: user._id,
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: 4,
|
||||
category: 'behavior'
|
||||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('user.items.pets')),
|
||||
message: i18n.t('petsReleased'),
|
||||
};
|
||||
if (analytics != null) {
|
||||
analytics.track('release pets', analyticsData);
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, user) : void 0;
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user