mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
* client/tasks/user: (create dropdown) change icon color on menuitem hover Previously the color was only changing when you hovered over the text or icon. This change changes the icon color when you hover anywhere over the `menuitem` * client/shops/market: fix search field in market * Hide drawer sliders if number of items for type is empty * Move drawer-help-text icon down to line up vertically with text * Add TODO for error thrown when trying to sell special item types * client/tasks/taskModal: display all selected tags for task * i18n/groups: religous to religious * client/shops/market: Add error message to empty drawer slider * Create new locale file to hold inventory locales * client/tasks/user: Revert change to create dropdown * Revert tag changes This will be picked up in a separate PR. * Fix missing space before function paren
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import content from '../content/index';
|
|
import i18n from '../i18n';
|
|
import get from 'lodash/get';
|
|
import pick from 'lodash/pick';
|
|
import splitWhitespace from '../libs/splitWhitespace';
|
|
import {
|
|
NotFound,
|
|
NotAuthorized,
|
|
BadRequest,
|
|
} from '../libs/errors';
|
|
|
|
// @TODO: 'special' type throws NotAuthorized error
|
|
const ACCEPTEDTYPES = ['eggs', 'hatchingPotions', 'food'];
|
|
|
|
module.exports = function sell (user, req = {}) {
|
|
let key = get(req.params, 'key');
|
|
let type = get(req.params, 'type');
|
|
let amount = get(req.query, 'amount', 1);
|
|
|
|
if (!type) {
|
|
throw new BadRequest(i18n.t('typeRequired', req.language));
|
|
}
|
|
|
|
if (!key) {
|
|
throw new BadRequest(i18n.t('keyRequired', req.language));
|
|
}
|
|
|
|
if (ACCEPTEDTYPES.indexOf(type) === -1) {
|
|
throw new NotAuthorized(i18n.t('typeNotSellable', {acceptedTypes: ACCEPTEDTYPES.join(', ')}, req.language));
|
|
}
|
|
|
|
if (!user.items[type][key]) {
|
|
throw new NotFound(i18n.t('userItemsKeyNotFound', {type}, req.language));
|
|
}
|
|
|
|
let currentAmount = user.items[type][key];
|
|
|
|
if (amount > currentAmount) {
|
|
throw new NotFound(i18n.t('userItemsNotEnough', {type}, req.language));
|
|
}
|
|
|
|
user.items[type][key] -= amount;
|
|
user.stats.gp += content[type][key].value * amount;
|
|
|
|
return [
|
|
pick(user, splitWhitespace('stats items')),
|
|
];
|
|
};
|