aboutsummaryrefslogtreecommitdiff
path: root/interface/routes/index.js
blob: 12cd0881806aa2058a18f94cd82563254e697633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require("express");
const router = express.Router();
const citizensController = require("../controllers/citizens.controller");
const api = require('./api');

// Setup api routes
router.use('/api', api);


router.get('/', (req, res) => {
    Promise.all([citizensController.findGenderDistribution()]).then(results => {
        const [genderDistribution] = results;
        res.render('index', {
            title: 'Home Page',
            genderDistribution
        });
    });
});

router.get("/citizens", (req, res) => {
    // Get the citizens from the database
    citizensController.findXCitizens().then(citizens => {
        res.render("citizens", {
            citizens: citizens,
            title: "Citizens Data"
        });
    });
});

// export the router
module.exports = router;