2016-03-07 22:02:42 +00:00
|
|
|
import content from '../content/index';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import splitWhitespace from '../libs/splitWhitespace';
|
|
|
|
|
|
2016-03-08 16:45:14 +00:00
|
|
|
module.exports = function(user, req, cb) {
|
2016-03-07 22:02:42 +00:00
|
|
|
var key, ref, type;
|
|
|
|
|
ref = req.params, key = ref.key, type = ref.type;
|
|
|
|
|
if (type !== 'eggs' && type !== 'hatchingPotions' && type !== 'food') {
|
2016-03-08 16:45:14 +00:00
|
|
|
return typeof cb === "function" ? cb({
|
2016-03-07 22:02:42 +00:00
|
|
|
code: 404,
|
2016-03-08 16:45:14 +00:00
|
|
|
message: ":type not found. Must bes in [eggs, hatchingPotions, food]"
|
2016-03-07 22:02:42 +00:00
|
|
|
}) : void 0;
|
|
|
|
|
}
|
|
|
|
|
if (!user.items[type][key]) {
|
2016-03-08 16:45:14 +00:00
|
|
|
return typeof cb === "function" ? cb({
|
2016-03-07 22:02:42 +00:00
|
|
|
code: 404,
|
2016-03-08 16:45:14 +00:00
|
|
|
message: ":key not found for user.items." + type
|
2016-03-07 22:02:42 +00:00
|
|
|
}) : void 0;
|
|
|
|
|
}
|
|
|
|
|
user.items[type][key]--;
|
|
|
|
|
user.stats.gp += content[type][key].value;
|
2016-03-08 16:45:14 +00:00
|
|
|
return typeof cb === "function" ? cb(null, _.pick(user, splitWhitespace('stats items'))) : void 0;
|
2016-03-07 22:02:42 +00:00
|
|
|
};
|