From 4c385d1dc172325964fd599b5a7ec377e41b48d5 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Thu, 13 Apr 2017 12:33:31 +0200 Subject: [PATCH] Added function for verifing a stray, this also calls the py script for moving the files to correct place. --- src/seasoned/strayRepository.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/seasoned/strayRepository.js b/src/seasoned/strayRepository.js index 5048ab8..297c0aa 100644 --- a/src/seasoned/strayRepository.js +++ b/src/seasoned/strayRepository.js @@ -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); + }) } }