Added function for verifing a stray, this also calls the py script for moving the files to correct place.
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
const assert = require('assert');
|
||||
const Stray = require('src/seasoned/stray');
|
||||
const establishedDatabase = require('src/database/database');
|
||||
var pythonShell = require('python-shell');
|
||||
|
||||
function foo(e) {
|
||||
throw('Foooo');
|
||||
}
|
||||
|
||||
class StrayRepository {
|
||||
|
||||
@@ -9,6 +14,7 @@ class StrayRepository {
|
||||
this.queries = {
|
||||
'read': 'SELECT * FROM stray_eps WHERE id = ?',
|
||||
'readAll': 'SELECT id, name, season, episode FROM stray_eps',
|
||||
'checkVerified': 'SELECT id FROM stray_eps WHERE verified = 0 AND id = ?',
|
||||
'verify': 'UPDATE stray_eps SET verified = 1 WHERE id = ?',
|
||||
};
|
||||
}
|
||||
@@ -32,7 +38,21 @@ class StrayRepository {
|
||||
}
|
||||
|
||||
verifyStray(strayId) {
|
||||
return this.database.run(this.queries.verify, strayId);
|
||||
return this.database.get(this.queries.checkVerified, strayId).then((row) => {
|
||||
assert.notEqual(row, undefined, `Stray '${strayId}' already verified.`);
|
||||
|
||||
var options = {
|
||||
args: [strayId]
|
||||
}
|
||||
|
||||
pythonShell.run('moveSeasoned.py', options, function (err, results) {
|
||||
if (err) throw err;
|
||||
// results is an array consisting of messages collected during execution
|
||||
console.log('results: %j', results);
|
||||
});
|
||||
|
||||
return this.database.run(this.queries.verify, strayId);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user