From f2d32fe72e8859833bddec13cf411d1e12914e2a Mon Sep 17 00:00:00 2001 From: iamBadgers Date: Sat, 18 May 2024 19:03:13 -0700 Subject: [PATCH] filter for character list --- backend/src/app.ts | 13 ++++++++++--- frontend/src/App.vue | 1 + frontend/src/vues/CharacterList.vue | 22 ++++++++++++++++++++-- frontend/src/vues/GameList.vue | 8 +++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index ccdf91d..6450863 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -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 }) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 0833ea6..e37e74e 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -2,6 +2,7 @@ + Server Stats Games Characters GMs diff --git a/frontend/src/vues/CharacterList.vue b/frontend/src/vues/CharacterList.vue index 621b1ea..1a332ae 100644 --- a/frontend/src/vues/CharacterList.vue +++ b/frontend/src/vues/CharacterList.vue @@ -1,4 +1,11 @@