Last active
April 25, 2017 22:54
-
-
Save jaygraygray/b1d916fdb94369fd2a9c3eea939ac1ac to your computer and use it in GitHub Desktop.
Back end controller for handling all requests related to articles.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GetBookmarks : function(req, res) { | |
var results = [] | |
// | |
// Get array of IDs for specific user | |
// | |
db.query("SELECT bookmarks_list FROM users WHERE id="+req.params.user_id, function(err, resp) { | |
if (err) {console.log(err)} else { | |
var bookmarks = resp[0].bookmarks_list.split(',') | |
// | |
// Select individual article | |
// based on each index of bookmarks array | |
// | |
for (var i = 0; i < bookmarks.length; i++) { | |
(function(i) { | |
db.query("select * from articles where id = " + bookmarks[i] + "ORDER BY id DESC", | |
function(err1, resp1) { | |
if (err) { console.log(err) } else { | |
if (i == bookmarks.length-1) { | |
results.push(resp1) | |
res.send(results) | |
} else { | |
results.push(resp1) | |
} | |
} | |
}) | |
})(i) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment