clean up routes

This commit is contained in:
Shannon Sterz 2016-02-25 19:40:44 +01:00
parent 5ee010bbf8
commit a85ae2fe31

View file

@ -8,7 +8,7 @@ var auth = jwt({secret: config.crypto_secret, userProperty: 'payload'});
var router = express.Router();
// Database models
var rc_db = new models.RCDB();
var rcdb = new models.RCDB();
var users = new models.Users();
// Arduino communications
@ -23,19 +23,34 @@ router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.post('/sendRC', auth, function (req, res, next){
rc.send(req.body.code);
res.send(req.body);
});
// RC Routes
router.get('/getRCs', auth, function (req, res, next) {
rc_db.findAll(function (error, results, fields) {
rcdb.findAll(function (error, results, fields) {
if(error){ console.log(error); return(next); }
res.json(results);
});
});
router.post('/sendRC', auth, function (req, res, next){
rc.send(req.body.code);
res.send('Success!');
});
router.post('/addRC', auth, function (req, res, next){
rcdb.add(req.body.rc, function (error, result) {
if(error) {console.log(error); return(next);}
res.json(result);
});
});
router.post('/deleteRC', auth, function (req, res, next){
rcdb.delete(req.body.id, function (error, result) {
if(error) {console.log(error); return(next);}
res.json(result);
});
});
// IR Routes
router.get('/irTest', auth, function (req, res) {
arduino.write(new Buffer('X0' + String.fromCharCode(4) + String.fromCharCode(12) + String.fromCharCode(0)+String.fromCharCode(0)+String.fromCharCode(2689 / 256) + String.fromCharCode(2689 % 256),'ascii'));
res.send('switch light');