src holds all controllers, config and api

This commit is contained in:
Kevin Midboe
2017-04-12 22:20:31 +02:00
parent 35146a5964
commit 6c29e59b2b
14 changed files with 361 additions and 0 deletions

7
src/seasoned/stray.js Normal file
View File

@@ -0,0 +1,7 @@
class Stray {
constructor(id) {
this.id = id;
}
}
module.exports = Stray;

View File

@@ -0,0 +1,39 @@
const assert = require('assert');
const Stray = require('src/seasoned/stray');
const establishedDatabase = require('src/database/database');
class StrayRepository {
constructor(database) {
this.database = database || establishedDatabase;
this.queries = {
'read': 'SELECT * FROM stray_eps WHERE id = ?',
'readAll': 'SELECT id, name, season, episode FROM stray_eps',
'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
};
}
read(strayId) {
return this.database.get(this.queries.read, strayId).then((row) => {
assert.notEqual(row, undefined, `Could not find list with id ${strayId}.`);
return row;
})
}
readAll() {
return this.database.all(this.queries.readAll).then(rows =>
rows.map((row) => {
const stray = new Stray(row.id);
stray.name = row.name;
stray.season = row.season;
stray.episode = row.episode;
return stray;
}))
}
verifyStray(strayId) {
return this.database.run(this.queries.verify, strayId);
}
}
module.exports = StrayRepository;