mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
start splitting ops (readCard has tests)
This commit is contained in:
@@ -510,6 +510,8 @@ TODO
|
||||
* Move to $resource!
|
||||
*/
|
||||
|
||||
import importedOps from './ops';
|
||||
|
||||
api.wrap = function(user, main) {
|
||||
if (main == null) {
|
||||
main = true;
|
||||
@@ -1799,16 +1801,7 @@ api.wrap = function(user, main) {
|
||||
}
|
||||
return typeof cb === "function" ? cb(null, _.pick(user, $w('stats'))) : void 0;
|
||||
},
|
||||
readCard: function(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");
|
||||
}
|
||||
user.flags.cardReceived = false;
|
||||
return typeof cb === "function" ? cb(null, 'items.special flags.cardReceived') : void 0;
|
||||
},
|
||||
readCard: _.partial(importedOps.readCard, user),
|
||||
openMysteryItem: function(req, cb, analytics) {
|
||||
var analyticsData, item, ref, ref1;
|
||||
item = (ref = user.purchased.plan) != null ? (ref1 = ref.mysteryItems) != null ? ref1.shift() : void 0 : void 0;
|
||||
|
||||
5
common/script/ops/index.js
Normal file
5
common/script/ops/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import readCard from './readCard';
|
||||
|
||||
module.exports = {
|
||||
readCard,
|
||||
};
|
||||
9
common/script/ops/readCard.js
Normal file
9
common/script/ops/readCard.js
Normal 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');
|
||||
};
|
||||
Reference in New Issue
Block a user