{"size": 846, "ext": "js", "max_stars_repo_path": "routes/control.js", "max_stars_repo_name": "paulrizzo/garden-bot-node", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "routes/control.js", "max_issues_repo_name": "paulrizzo/garden-bot-node", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "routes/control.js", "max_forks_repo_name": "paulrizzo/garden-bot-node", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.2, "max_line_length": 75, "alphanum_fraction": 0.621749409}
var express = require('express');
var actionService = require('../services/bot-service');
var ACTIONS = require('../services/bot-actions');
var router = express.Router();

/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('control', {
        title: 'Garden Bot',
        actions: Object.entries(ACTIONS)
    });
});

router.post('/action', function (req, res, next) {
    actionService.toggle(req.body.action);
    res.send('success');
});

router.get('/action/:action', async function (req, res, next) {
    try {
        let data = await actionService.getActionState(req.params.action);
        console.log('action ' + req.params.action + ' result ' + data);
        res.send(data);
    } catch (e) {
        console.log('Error getting state for action ' + req.params.action);
    }
});

module.exports = router;
