pagination for character list

This commit is contained in:
jmosrael@gmail.com
2024-05-05 16:04:12 -07:00
parent b411065751
commit 28d06df844
2 changed files with 28 additions and 9 deletions

View File

@@ -79,8 +79,17 @@ app.post('/api/character', jsonParser, async (req, res) => {
const orderBy = req.body.orderBy
const count = req.body.count
const characterData = await Character.findAll({
offset: page * count,
limit: count
})
const pageCount = Math.ceil(await Character.count() / count)
console.log(characterData)
console.log(pageCount)
res.setHeader('Content-Type', 'application/json')
res.send(await Character.findAll({ offset: page * count, limit: count }))
res.json({characterData, pageCount})
})
app.get('/api/game/:characterId', async (req, res) => {