refactory: status controller

This commit is contained in:
Gustavo Cortez 2014-01-19 05:30:22 -03:00
parent 9db25a988e
commit 027935844a
1 changed files with 36 additions and 35 deletions

View File

@ -15,43 +15,44 @@ exports.show = function(req, res, next) {
res.status(400).send('Bad Request'); res.status(400).send('Bad Request');
} }
else { else {
var s = req.query.q; var option = req.query.q;
var d = Status.new(); var statusObject = Status.new();
if (s === 'getInfo') { switch(option) {
d.getInfo(function(err) { case 'getInfo':
statusObject.getInfo(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(statusObject);
}); });
} break;
else if (s === 'getDifficulty') { case 'getDifficulty':
d.getDifficulty(function(err) { statusObject.getDifficulty(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(statusObject);
}); });
} break;
else if (s === 'getTxOutSetInfo') { case 'getTxOutSetInfo':
d.getTxOutSetInfo(function(err) { statusObject.getTxOutSetInfo(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(statusObject);
}); });
} break;
else if (s === 'getBestBlockHash') { case 'getBestBlockHash':
d.getBestBlockHash(function(err) { statusObject.getBestBlockHash(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(statusObject);
}); });
} break;
else if (s === 'getLastBlockHash') { case 'getLastBlockHash':
d.getLastBlockHash(function(err) { statusObject.getLastBlockHash(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(statusObject);
}); });
} break;
default:
else {
res.status(400).send('Bad Request'); res.status(400).send('Bad Request');
} }
} }
}; };