[#1431] add temporary server-based pet-purchasing mechanism. Lotsa cleanup /

refactoring to be had here
This commit is contained in:
Tyler Renelle
2013-09-06 00:28:18 -04:00
parent 812ba3a339
commit ef69309b0c
5 changed files with 44 additions and 26 deletions
+24
View File
@@ -16,6 +16,30 @@ var User = require('./../models/user').model;
var Group = require('./../models/group').model;
var api = module.exports;
// FIXME put this in a proper location
api.marketBuy = function(req, res, next){
var user = res.locals.user,
type = req.query.type,
item = req.body;
if (!_.contains(['hatchingPotion', 'egg'], req.query.type))
return res.json(400, {err: "Type must be in 'hatchingPotion' or 'egg'"});
var item;
if (type == 'egg'){
if (!user.items && !user.items.eggs) user.items.eggs = [];
user.items.eggs.push(item);
} else {
if (!user.items && !user.items.hatchingPotions) user.items.hatchingPotions = [];
user.items.hatchingPotions.push(item.name);
}
user.markModified('items'); // I still don't get when this is necessary and when not..
user.balance -= (item.value/4);
user.save(function(err, saved){
if (err) return res.json(500, {err:err});
res.json(saved);
})
}
/*
------------------------------------------------------------------------