mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
* Moved buy tests * Added mystery buy to buy.js * Added quest purchasing to buy * Added buy special * Moved integration tests to buy folder * Removed buyGear dependency * Removed buyArmoire dependency * Removed buyHealthPotion dependency * Removed myster, quest and special dependency * Replaced functions with factory * Added bulk purchasing to common * Added bulk purchasing to the api * Added bulk purchasing to client * Refactored purchasing function to reduce long method * Added bulk purchase to gem purchases * Added bulk purchasing to api * Added bulk purchasing to gem items on client * Removed bulk from equipment * Removed recentlyPurchased * Fixed style issues and prevented puchasing more gems than are left * Fixed lint * Fixed missing keys * Fixed gem amount notice * Added quest modal to pinned item * Added bulk purchase to gem modal * Fixed styles * Fixed bulk purchase for spells * Fixed modal size * Hid autofill
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
import i18n from '../i18n';
|
|
import get from 'lodash/get';
|
|
import {
|
|
BadRequest,
|
|
} from '../libs/errors';
|
|
import buyHealthPotion from './buyHealthPotion';
|
|
import buyArmoire from './buyArmoire';
|
|
import buyGear from './buyGear';
|
|
import buyMysterySet from './buyMysterySet';
|
|
import buyQuest from './buyQuest';
|
|
import buySpecialSpell from './buySpecialSpell';
|
|
|
|
// @TODO: remove the req option style. Dependency on express structure is an anti-pattern
|
|
// We should either have more parms or a set structure validated by a Type checker
|
|
|
|
// @TODO: when we are sure buy is the only function used, let's move the buy files to a folder
|
|
|
|
module.exports = function buy (user, req = {}, analytics) {
|
|
let key = get(req, 'params.key');
|
|
if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language));
|
|
|
|
// @TODO: Slowly remove the need for key and use type instead
|
|
// This should evenutally be the 'factory' function with vendor classes
|
|
let type = get(req, 'type');
|
|
if (!type) type = key;
|
|
|
|
// @TODO: For now, builk purchasing is here, but we should probably have a parent vendor
|
|
// class that calls the factory and handles larger operations. If there is more than just bulk
|
|
let quantity = 1;
|
|
if (req.quantity) quantity = req.quantity;
|
|
|
|
let buyRes;
|
|
|
|
for (let i = 0; i < quantity; i += 1) {
|
|
if (type === 'potion') {
|
|
buyRes = buyHealthPotion(user, req, analytics);
|
|
} else if (type === 'armoire') {
|
|
buyRes = buyArmoire(user, req, analytics);
|
|
} else if (type === 'mystery') {
|
|
buyRes = buyMysterySet(user, req, analytics);
|
|
} else if (type === 'quest') {
|
|
buyRes = buyQuest(user, req, analytics);
|
|
} else if (type === 'special') {
|
|
buyRes = buySpecialSpell(user, req, analytics);
|
|
} else {
|
|
buyRes = buyGear(user, req, analytics);
|
|
}
|
|
}
|
|
|
|
return buyRes;
|
|
};
|