filter for character list

This commit is contained in:
iamBadgers
2024-05-18 19:03:13 -07:00
parent 8809a94160
commit f2d32fe72e
4 changed files with 38 additions and 6 deletions

View File

@@ -20,14 +20,21 @@ app.get('/api/character/:characterId', async (req, res) => {
app.post('/api/character', jsonParser, async (req, res) => {
const page = req.body.page
const orderBy = req.body.orderBy
const orderBy = req.body.orderBy ? obp.parse(req.body.orderBy) : ['id']
const count = req.body.count
const filter = req.body.filter ? fp.parse(req.body.filter) : {}
const characterData = await Character.findAll({
offset: page * count,
limit: count
limit: count,
order: orderBy,
where: filter
})
const pageCount = Math.ceil((await Character.count()) / count)
const pageCount = Math.ceil(
(await Character.count({
where: filter
})) / count
)
res.setHeader('Content-Type', 'application/json')
res.json({ characterData, pageCount })