update game list to use sortable columns

This commit is contained in:
iamBadgers
2024-06-11 16:35:48 -07:00
parent 2db71661f0
commit 976e12d91a
4 changed files with 67 additions and 42 deletions

View File

@@ -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({

View File

@@ -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.')