Created
July 23, 2012 11:15
-
-
Save Alan01252/3163135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var account_controller = Object.create(global.Crud, | |
{ | |
/** | |
* Overload the create method | |
*/ | |
'create': function(req,res){ | |
Crud.create(req,res,function(instance) { | |
if(typeof instance == "object") | |
socket.send('newActivity', {'instance' : instance, 'req': req, 'res' :res}); | |
}); | |
}, | |
/** | |
* Overload the update method | |
*/ | |
'update': function(req,res){ | |
_self.updateClientTiers(req,res,function(){ | |
Crud.update(req,res); | |
}); | |
}, | |
/** | |
* If the account changes tier we need to update all its clients | |
*/ | |
'updateClientTiers': function(req,res,callback){ | |
var model = global.RESTmodules['client'].model; | |
if(typeof(req.body.tier) == 'undefined') | |
return callback(); | |
model.update({idAccount: req.params.id}, {tier: req.body.tier}, {multi: true}, function(err) { | |
if(err){ | |
winston.error('DB Error: ' + err); | |
res.json({success: false},500); | |
return; | |
} | |
return callback(); | |
}); | |
} | |
}); | |
module.exports = account_controller; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment