Socialify

Folder ..

Viewing geography.js
53 lines (42 loc) • 1.5 KB

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require("express");
const router = express.Router();
const stateController = require("../../controllers/state.controller");
const mandalController = require("../../controllers/mandal.controller");
const villageController = require("../../controllers/village.controller");
const districtController = require("../../controllers/district.controller");


router.get("/states", (req, res) => {
    stateController.allStates().then(states => {
        res.send(states);        
    });
});

router.get("/districts/:state_id", (req, res) => {
    const state_id = req.params.state_id;
    districtController.allDistrictsByStateId(state_id).then(districts => {
        if (districts) {
            res.send(districts);
        } else {
            res.status(400).json({ message: "No districts found" });
        }
    });
});
router.get("/mandals/:district_id", (req, res) => {
    const district_id = req.params.district_id;
    mandalController.allMandalsByDistrictId(district_id).then(mandals => {
        if (mandals) {
            res.send(mandals);
        } else {
            res.status(400).json({ message: "No mandals found" });
        }
    });
});

router.get("/villages/:mandal_id", (req, res) => {
    const mandal_id = req.params.mandal_id;
    villageController.allVillagesByMandalId(mandal_id).then(villages => {
        if (villages) {
            res.send(villages);
        } else {
            res.status(400).json({ message: "No villages found" });
        }
    });
});




module.exports = router;