var RippleAddress = require('../models/ripple_address');

function respondToValidationErrors(req, res) {
	var errors = req.validationErrors();
	if (errors) {
		res.end({ error: util.inspect(errors) }, 400)
		return;
	}
}

module.exports = (function(){
  function userIndex(req, res) {
    RippleAddress.findAll({ where: { user_id: req.params.id }}).complete(function(err, addresses) {
      res.send({ success: true, ripple_addresses: addresses });
    })
	}

  function create(req, res) {
		req.checkBody('userId', 'Invalid bankAccountId')
			.notEmpty().isInt();
		req.checkBody('rippleAddress', 'Invalid currency')
			.notEmpty().isAlpha();
		req.checkBody('cashAmount', 'Invalid cashAmount')
			.notEmpty().isFloat();

		respondToValidationErrors(req, res);

		RippleAddress.create({
			user_id: req.body.userId,
			address: req.body.rippleAddress
		})
		.success(function(address){
			res.send(address);
		})
		.error(function(err){
			res.send({ error: err });
		});
	}

  function index(req,res) {
		RippleAddress.findAll()
		.success(function(addresses){
			res.send(addresses);
		})
		.error(function(err){
			res.send({ error: err });
		});
  }

  return {
		userIndex: userIndex,
		create: create,
		index: index
  }
})();

var RippleAddress = require('../models/ripple_address');

module.exports = (function(){
  function create(req, res) {
    req.validate('user_id', 'isInt');
    req.validate('ripple_address', 'isAlpha');
		req.validate('cash_amount', 'isFloat');

    if (req.user.admin || (req.user.id == req.body.user_id)) {
      RippleAddress.create({
        user_id: req.body.userId,
        address: req.body.rippleAddress
      }).complete(function(err, address){
        res.send({ ripple_address: address });
      });
    } else {
      res.status(401);
      res.send('Unauthorized');
    }
	}

  function index(req,res) {
    if (req.user.admin) {
      RippleAddress.findAll().complete(function(err, addresses) {
        res.send({ ripple_addresses: addresses });
      });
    } else {
      RippleAddress.findAll({ where: { user_id: req.user.id }})
        .complete(function(err, addresses) {
          res.send({ ripple_addresses: addresses });
      });
    }
  }

  return {
		create: create,
		index: index
  }
})();

Use new validations, clean up ripple addresses express controller.
[FEATURE] Use new validations, clean up ripple addresses express controller.
