update game list to use sortable columns
This commit is contained in:
@@ -25,7 +25,7 @@ export function addCharacterApis(app, jsonParser) {
|
||||
|
||||
const page = req.body.page
|
||||
const orderBy = req.body.orderBy ? obp.parse(req.body.orderBy) : ['id']
|
||||
const count = req.body.count
|
||||
const count = req.body.count || 10
|
||||
const filter = req.body.filter ? fp.parse(req.body.filter) : {}
|
||||
|
||||
const characterData = await Character.findAll({
|
||||
|
||||
@@ -20,6 +20,7 @@ export function addGameApis(app, jsonParser) {
|
||||
try {
|
||||
const fp = new FilterParser()
|
||||
const obp = new OrderByParser()
|
||||
|
||||
const page = req.body.page || 0
|
||||
const orderBy = req.body.orderBy ? obp.parse(req.body.orderBy) : ['id']
|
||||
const count = req.body.count || 10
|
||||
@@ -31,14 +32,15 @@ export function addGameApis(app, jsonParser) {
|
||||
order: orderBy,
|
||||
where: filter
|
||||
})
|
||||
const pageCount = Math.ceil(
|
||||
(await Game.count({
|
||||
const totalCount = await Game.count({
|
||||
where: filter
|
||||
})) / count
|
||||
})
|
||||
const pageCount = Math.ceil(
|
||||
totalCount / count
|
||||
)
|
||||
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.send({ gameData, pageCount })
|
||||
res.send({ gameData, pageCount, totalCount })
|
||||
} catch (e) {
|
||||
if (e instanceof ParsingError) {
|
||||
res.status(400).send('Could not parse filter.')
|
||||
|
||||
Reference in New Issue
Block a user