Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. router.post('/getStances', function(req, res, next) {
  2. var text = '{"success":"0"}';
  3. text = queries.getStances(req.body.issues[0], req.body.issues[1], req.body.issues[2], req.body.issues[3]);
  4. var obj = JSON.parse(result);
  5. res.send(obj);
  6. });
  7.  
  8. getStances: function (a, b, c, d) {
  9. var sendback = '{"stances":[';
  10. sendback += '{"1":[';
  11. var querytext = "SELECT * FROM allIssues WHERE topicname = '"+ a +"'";
  12. query = client.query(querytext,function (callback) {
  13. query.on('row', (row) => {
  14. sendback += "{" + '"'+row['topicstance']+'"' + " : " + '"'+ row['topicdescription'] + '"'+ "} , ";
  15. console.log(sendback);
  16. });
  17. });
  18.  
  19. querytext = "SELECT * FROM allIssues WHERE topicname = '"+ b +"'";
  20. query = client.query(querytext);
  21. query.on('row', (row) => {
  22. sendback += "{" + '"'+ row['topicstance'] + '"'+ " : " + '"'+ row['topicdescription'] + '"'+ "} , ";
  23. });
  24. query.on('end', () => {
  25. sendback += "]}";
  26. sendback += "]}";
  27. client.end();
  28. return sendback;
  29. });
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement