Advertisement
anapitalai

Untitled

Nov 4th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //geography data
  2. router.get('/crimes', function (req, res) {
  3. var client = new pg.Client(conString);
  4. client.connect();
  5. var query = client.query(geo_query);
  6. query.on("row", function (row, result) {
  7. result.addRow(row);
  8. });
  9. query.on("end", function (result) {
  10. res.send(result.rows[0].row_to_json);
  11. res.end();
  12. });
  13. });
  14.  
  15.  
  16. router.post('/crimes', function (req, res) {
  17. var client = new pg.Client(conString);
  18. client.connect();
  19. const { enteredcrime_type, enteredstreet, lon, lat } = req.body;
  20. const crime_type = enteredcrime_type;
  21. const street = enteredstreet;
  22. var query = client.query(insert_lonlat, [crime_type, street, lon, lat], error => {
  23. if (error) {
  24. throw error
  25. } else {
  26. //runs the update of the where_is col
  27. client.query(geo_update);
  28. res.status(201).json({ status: 'success', message: 'Crime Data added.' });
  29. }
  30. })
  31.  
  32. console.log(req.body);
  33.  
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement