Skip to content

Instantly share code, notes, and snippets.

@Alan01252
Created July 23, 2012 11:15
Show Gist options
  • Save Alan01252/3163135 to your computer and use it in GitHub Desktop.
Save Alan01252/3163135 to your computer and use it in GitHub Desktop.
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