diff options
| author | Bobby <[email protected]> | 2022-05-03 22:04:04 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-05-03 22:04:04 -0400 |
| commit | f1b9662122abed09ccf74b2eda034e7a45730e60 (patch) | |
| tree | 2e34ce476542d17871791d19fb45fd6a20d61bfa /interface/routes | |
| parent | 00826988bf4d1fba76c0a65fa850639844ef61a4 (diff) | |
| download | Welfare-Schemes-DMQL-f1b9662122abed09ccf74b2eda034e7a45730e60.tar.xz Welfare-Schemes-DMQL-f1b9662122abed09ccf74b2eda034e7a45730e60.zip | |
citizens pagination
Diffstat (limited to 'interface/routes')
| -rw-r--r-- | interface/routes/api/citizens.js | 6 | ||||
| -rw-r--r-- | interface/routes/index.js | 14 |
2 files changed, 16 insertions, 4 deletions
diff --git a/interface/routes/api/citizens.js b/interface/routes/api/citizens.js index fc98928..c6c6425 100644 --- a/interface/routes/api/citizens.js +++ b/interface/routes/api/citizens.js @@ -3,6 +3,12 @@ const router = express.Router(); const citizensController = require("../../controllers/citizens.controller"); +router.get('/count', (req, res) => { + citizensController.getCountOfCitizens().then(count => { + res.json({ count }); + }); +}); + router.post("/edit", (req, res) => { const { citizen_id, address, mobile_num, dob, marital_status } = req.body; if (!citizen_id || !address || !mobile_num || !dob || !marital_status) { diff --git a/interface/routes/index.js b/interface/routes/index.js index b99abbf..c75c2c0 100644 --- a/interface/routes/index.js +++ b/interface/routes/index.js @@ -22,11 +22,17 @@ router.get('/', (req, res) => { }); router.get("/citizens", (req, res) => { + // Get the limit and offset from the query string + const limit = parseInt(req.query.limit, 10) || 10; + const page = req.query.page ? (req.query.page - 1) * limit : 0; + // Get the citizens from the database - citizensController.findXCitizens().then(citizens => { - res.render("citizens", { - citizens: citizens, - title: "Citizens Data" + Promise.all([citizensController.findXCitizens(limit, page), citizensController.getCountOfCitizens()]).then(results => { + const [citizens, count] = results; + res.render('citizens', { + title: 'Citizens', + citizens, + count: count[0].count, }); }); }); |
