start splitting ops (readCard has tests)

This commit is contained in:
Matteo Pagliazzi
2016-03-07 19:32:49 +01:00
parent 34057c375b
commit 8437c21a51
3 changed files with 17 additions and 10 deletions

View File

@@ -510,6 +510,8 @@ TODO
* Move to $resource! * Move to $resource!
*/ */
import importedOps from './ops';
api.wrap = function(user, main) { api.wrap = function(user, main) {
if (main == null) { if (main == null) {
main = true; main = true;
@@ -1799,16 +1801,7 @@ api.wrap = function(user, main) {
} }
return typeof cb === "function" ? cb(null, _.pick(user, $w('stats'))) : void 0; return typeof cb === "function" ? cb(null, _.pick(user, $w('stats'))) : void 0;
}, },
readCard: function(req, cb) { readCard: _.partial(importedOps.readCard, user),
var cardType;
cardType = req.params.cardType;
user.items.special[cardType + "Received"].shift();
if (typeof user.markModified === "function") {
user.markModified("items.special." + cardType + "Received");
}
user.flags.cardReceived = false;
return typeof cb === "function" ? cb(null, 'items.special flags.cardReceived') : void 0;
},
openMysteryItem: function(req, cb, analytics) { openMysteryItem: function(req, cb, analytics) {
var analyticsData, item, ref, ref1; var analyticsData, item, ref, ref1;
item = (ref = user.purchased.plan) != null ? (ref1 = ref.mysteryItems) != null ? ref1.shift() : void 0 : void 0; item = (ref = user.purchased.plan) != null ? (ref1 = ref.mysteryItems) != null ? ref1.shift() : void 0 : void 0;

View File

@@ -0,0 +1,5 @@
import readCard from './readCard';
module.exports = {
readCard,
};

View File

@@ -0,0 +1,9 @@
module.exports = function readCard (user, req, cb) {
let cardType = req.params.cardType;
user.items.special[`${cardType}Received`].shift();
if (user.markModified) {
user.markModified(`items.special.${cardType}Received`);
}
user.flags.cardReceived = false;
if (cb) cb(null, 'items.special flags.cardReceived');
};