diff --git a/backend/src/characterservice.ts b/backend/src/characterservice.ts index f2c0790..7cce42c 100644 --- a/backend/src/characterservice.ts +++ b/backend/src/characterservice.ts @@ -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({ diff --git a/backend/src/gameservice.ts b/backend/src/gameservice.ts index 0ac3398..96140f7 100644 --- a/backend/src/gameservice.ts +++ b/backend/src/gameservice.ts @@ -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.') diff --git a/frontend/src/vues/CharacterList.vue b/frontend/src/vues/CharacterList.vue index 9c2fb39..33a08b7 100644 --- a/frontend/src/vues/CharacterList.vue +++ b/frontend/src/vues/CharacterList.vue @@ -12,7 +12,7 @@ :items="characters" :items-length="count" v-model:page="page" - @update:options="loadItems" + @update:options="loadData" >