Last active
July 20, 2018 15:12
-
-
Save amandeepmittal/e49845cb40a6e1b1ff9518209f25bf95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/:page', (req, res) => { | |
let limit = 50; // number of records per page | |
let offset = 0; | |
db.user.findAndCountAll() | |
.then((data) => { | |
let page = req.params.page; // page number | |
let pages = Math.ceil(data.count / limit); | |
offset = limit * (page - 1); | |
db.user.findAll({ | |
attributes: ['id', 'first_name', 'last_name', 'date_of_birth'], | |
limit: limit, | |
offset: offset, | |
$sort: { id: 1 } | |
}) | |
.then((users) => { | |
res.status(200).json({'result': users, 'count': data.count, 'pages': pages}); | |
}); | |
}) | |
.catch(function (error) { | |
res.status(500).send('Internal Server Error'); | |
}); | |
}); |
Yes, indeed. My mistake.
Correction done, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it's
req.params.page
instead, no? https://gist.github.com/amandeepmittal/e49845cb40a6e1b1ff9518209f25bf95#file-user-js-L6