diff --git a/src/seasoned/strayRepository.js b/src/seasoned/strayRepository.js index 6845dec..4f688ac 100644 --- a/src/seasoned/strayRepository.js +++ b/src/seasoned/strayRepository.js @@ -14,6 +14,7 @@ class StrayRepository { this.queries = { 'read': 'SELECT * FROM stray_eps WHERE id = ?', 'readAll': 'SELECT id, name, season, episode, verified FROM stray_eps', + 'readAllFiltered': 'SELECT id, name, season, episode, verified FROM stray_eps WHERE verified = ', 'checkVerified': 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?', 'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?', }; @@ -26,8 +27,12 @@ class StrayRepository { }) } - readAll() { - return this.database.all(this.queries.readAll).then(rows => + readAll(verified = null, page = 1) { + var dbSearchQuery = this.queries.readAll; + if (verified != null) { + dbSearchQuery = this.queries.readAllFiltered + verified.toString(); + } + return this.database.all(dbSearchQuery).then(rows => rows.map((row) => { const stray = new Stray(row.id); stray.name = row.name; diff --git a/src/webserver/controllers/seasoned/readStrays.js b/src/webserver/controllers/seasoned/readStrays.js index b347153..5e5193b 100644 --- a/src/webserver/controllers/seasoned/readStrays.js +++ b/src/webserver/controllers/seasoned/readStrays.js @@ -3,7 +3,8 @@ const strayRepository = new StrayRepository(); function readStraysController(req, res) { - strayRepository.readAll() + const { verified, page } = req.query; + strayRepository.readAll(verified, page) .then((strays) => { res.send(strays); })