Linted all seasoned scripts.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
class Stray {
|
class Stray {
|
||||||
constructor(id) {
|
constructor(id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Stray;
|
module.exports = Stray;
|
||||||
|
|||||||
@@ -1,67 +1,62 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const Stray = require('src/seasoned/stray');
|
const Stray = require('src/seasoned/stray');
|
||||||
const establishedDatabase = require('src/database/database');
|
const establishedDatabase = require('src/database/database');
|
||||||
var pythonShell = require('python-shell');
|
const pythonShell = require('python-shell');
|
||||||
|
|
||||||
function foo(e) {
|
|
||||||
throw('Foooo');
|
|
||||||
}
|
|
||||||
|
|
||||||
class StrayRepository {
|
class StrayRepository {
|
||||||
|
constructor(database) {
|
||||||
|
this.database = database || establishedDatabase;
|
||||||
|
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 = ?',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
constructor(database) {
|
read(strayId) {
|
||||||
this.database = database || establishedDatabase;
|
return this.database.get(this.queries.read, strayId).then((row) => {
|
||||||
this.queries = {
|
assert.notEqual(row, undefined, `Could not find list with id ${strayId}.`);
|
||||||
'read': 'SELECT * FROM stray_eps WHERE id = ?',
|
return row;
|
||||||
'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 = ?',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
read(strayId) {
|
readAll(verified = null) {
|
||||||
return this.database.get(this.queries.read, strayId).then((row) => {
|
let dbSearchQuery = this.queries.readAll;
|
||||||
assert.notEqual(row, undefined, `Could not find list with id ${strayId}.`);
|
if (verified != null) {
|
||||||
return row;
|
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;
|
||||||
|
stray.season = row.season;
|
||||||
|
stray.episode = row.episode;
|
||||||
|
stray.verified = row.verified;
|
||||||
|
return stray;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
readAll(verified = null, page = 1) {
|
verifyStray(strayId) {
|
||||||
var dbSearchQuery = this.queries.readAll;
|
return this.database.get(this.queries.checkVerified, strayId).then((row) => {
|
||||||
if (verified != null) {
|
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
|
||||||
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;
|
|
||||||
stray.season = row.season;
|
|
||||||
stray.episode = row.episode;
|
|
||||||
stray.verified = row.verified;
|
|
||||||
return stray;
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
verifyStray(strayId) {
|
const options = {
|
||||||
return this.database.get(this.queries.checkVerified, strayId).then((row) => {
|
pythonPath: '/usr/bin/python3',
|
||||||
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
|
args: [strayId],
|
||||||
|
};
|
||||||
|
|
||||||
var options = {
|
pythonShell.run('../app/moveSeasoned.py', options, (err, results) => {
|
||||||
pythonPath: '/usr/bin/python3',
|
if (err) throw err;
|
||||||
args: [strayId]
|
// TODO Add error handling!! StrayRepository.ERROR
|
||||||
}
|
// results is an array consisting of messages collected during execution
|
||||||
|
console.log('results: %j', results);
|
||||||
|
});
|
||||||
|
|
||||||
pythonShell.run('../app/moveSeasoned.py', options, function (err, results) {
|
return this.database.run(this.queries.verify, strayId);
|
||||||
if (err) throw err;
|
});
|
||||||
// TODO Add error handling!! StrayRepository.ERROR
|
}
|
||||||
// results is an array consisting of messages collected during execution
|
|
||||||
console.log('results: %j', results);
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.database.run(this.queries.verify, strayId);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = StrayRepository;
|
module.exports = StrayRepository;
|
||||||
|
|||||||
Reference in New Issue
Block a user