The async function for getting episodes now send response when the async function is done.

This commit is contained in:
Kevin Midboe
2017-04-06 17:42:28 +02:00
parent 97e062ef13
commit f3ef2ef15a

View File

@@ -31,18 +31,18 @@ router.get('/seasoned', function(req, res) {
var db = new sqlite3.Database(db_path); var db = new sqlite3.Database(db_path);
var returnMsg; var returnMsg;
var id = req.param('id'); var id = req.param('id');
db.serialize(function() {
db.get("SELECT * FROM stray_eps WHERE id = '" + id + "'", function(err, row) { function getEpisode(id, fn){
returnMsg = row; db.serialize(function() {
// res.json({message: row}); db.get("SELECT * FROM stray_eps WHERE id = '" + id + "'", function(err, row) {
// returnList.push(row.original, row.full_path, row.last_name); fn(row)
}), console.log(returnMsg); })
}), console.log(returnMsg); });
// console.log(returnMsg); }
// db.close();
db.close(); getEpisode(id, function(episode){
res.json({message: toString(returnMsg)}); res.json({episode}); // this is where you get the return value
//console.log(returnMsg); });
}); });
// more routes for our API will happen here // more routes for our API will happen here