filter for character list
This commit is contained in:
@@ -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 })
|
||||
|
||||
Reference in New Issue
Block a user