Added option for filtering in verified and page number when searching through all stray episodes.
This commit is contained in:
@@ -14,6 +14,7 @@ class StrayRepository {
|
|||||||
this.queries = {
|
this.queries = {
|
||||||
'read': 'SELECT * FROM stray_eps WHERE id = ?',
|
'read': 'SELECT * FROM stray_eps WHERE id = ?',
|
||||||
'readAll': 'SELECT id, name, season, episode, verified FROM stray_eps',
|
'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 = ?',
|
'checkVerified': 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?',
|
||||||
'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
|
'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
|
||||||
};
|
};
|
||||||
@@ -26,8 +27,12 @@ class StrayRepository {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
readAll() {
|
readAll(verified = null, page = 1) {
|
||||||
return this.database.all(this.queries.readAll).then(rows =>
|
var dbSearchQuery = this.queries.readAll;
|
||||||
|
if (verified != null) {
|
||||||
|
dbSearchQuery = this.queries.readAllFiltered + verified.toString();
|
||||||
|
}
|
||||||
|
return this.database.all(dbSearchQuery).then(rows =>
|
||||||
rows.map((row) => {
|
rows.map((row) => {
|
||||||
const stray = new Stray(row.id);
|
const stray = new Stray(row.id);
|
||||||
stray.name = row.name;
|
stray.name = row.name;
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ const strayRepository = new StrayRepository();
|
|||||||
|
|
||||||
|
|
||||||
function readStraysController(req, res) {
|
function readStraysController(req, res) {
|
||||||
strayRepository.readAll()
|
const { verified, page } = req.query;
|
||||||
|
strayRepository.readAll(verified, page)
|
||||||
.then((strays) => {
|
.then((strays) => {
|
||||||
res.send(strays);
|
res.send(strays);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user