From 027935844a4715962b8c34ce55fb7164295d7402 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Sun, 19 Jan 2014 05:30:22 -0300 Subject: [PATCH] refactory: status controller --- app/controllers/status.js | 71 ++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/app/controllers/status.js b/app/controllers/status.js index eb2f1ae..6fa8e9b 100644 --- a/app/controllers/status.js +++ b/app/controllers/status.js @@ -15,43 +15,44 @@ exports.show = function(req, res, next) { res.status(400).send('Bad Request'); } else { - var s = req.query.q; - var d = Status.new(); - - if (s === 'getInfo') { - d.getInfo(function(err) { - if (err) next(err); - res.jsonp(d); - }); - } - else if (s === 'getDifficulty') { - d.getDifficulty(function(err) { - if (err) next(err); - res.jsonp(d); - }); - } - else if (s === 'getTxOutSetInfo') { - d.getTxOutSetInfo(function(err) { - if (err) next(err); - res.jsonp(d); - }); - } - else if (s === 'getBestBlockHash') { - d.getBestBlockHash(function(err) { - if (err) next(err); - res.jsonp(d); - }); - } - else if (s === 'getLastBlockHash') { - d.getLastBlockHash(function(err) { - if (err) next(err); - res.jsonp(d); - }); - } + var option = req.query.q; + var statusObject = Status.new(); - else { - res.status(400).send('Bad Request'); + switch(option) { + case 'getInfo': + statusObject.getInfo(function(err) { + if (err) next(err); + res.jsonp(statusObject); + }); + break; + case 'getDifficulty': + statusObject.getDifficulty(function(err) { + if (err) next(err); + res.jsonp(statusObject); + }); + break; + case 'getTxOutSetInfo': + statusObject.getTxOutSetInfo(function(err) { + if (err) next(err); + res.jsonp(statusObject); + }); + break; + case 'getBestBlockHash': + statusObject.getBestBlockHash(function(err) { + if (err) next(err); + res.jsonp(statusObject); + }); + break; + case 'getLastBlockHash': + statusObject.getLastBlockHash(function(err) { + if (err) next(err); + res.jsonp(statusObject); + }); + break; + default: + res.status(400).send('Bad Request'); } } }; +