mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Ported read card, added unit tests, added read card route and integration tests
This commit is contained in:
@@ -1,10 +1,28 @@
|
||||
module.exports = function(user, req, cb) {
|
||||
var cardType;
|
||||
cardType = req.params.cardType;
|
||||
user.items.special[cardType + "Received"].shift();
|
||||
if (typeof user.markModified === "function") {
|
||||
user.markModified("items.special." + cardType + "Received");
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import _ from 'lodash';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import content from '../content/index';
|
||||
|
||||
module.exports = function readCard (user, req = {}) {
|
||||
let cardType = _.get(req.params, 'cardType');
|
||||
|
||||
if (!cardType) {
|
||||
throw new BadRequest(i18n.t('cardTypeRequired', req.language));
|
||||
}
|
||||
|
||||
if (_.keys(content.cardTypes).indexOf(cardType) === -1) {
|
||||
throw new NotAuthorized(i18n.t('cardTypeNotAllowed', req.language));
|
||||
}
|
||||
|
||||
user.items.special[`${cardType}Received`].shift();
|
||||
user.flags.cardReceived = false;
|
||||
return typeof cb === "function" ? cb(null, 'items.special flags.cardReceived') : void 0;
|
||||
|
||||
return {
|
||||
message: i18n.t('readCard', {cardType}, req.language),
|
||||
data: _.pick(user, splitWhitespace('items.special flags.cardReceived')),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user