const express = require('express');
const pg = require('pg');

const router = express.Router();

// SSL must be used to connect to the DB
const DB_URL = process.env.DATABASE_URL + '?ssl=true';

router.get('/db', (req, res) => {
  pg.connect(DB_URL, (err, client, done) => {
    if (err) {
      console.error(err);
      return;
    }
    client.query('SELECT * FROM test_table', (err, result) => {
      if (err) {
        console.error(err);
        res.send("Error " + err);
      } else {
        res.send(result.rows);
      }
    });
  });
})

module.exports = router;

@@ -191,23 +191,938 @@
 ';%0A%0A
-router.get('/db
+// A catch-all error%0Afunction generateGenericError() %7B%0A  return %7B%0A    title: %22Server Error%22,%0A    description: %22There was an error while processing your request.%22%0A  %7D;%0A%7D%0A%0A// Generates an error for a 404 resource%0Afunction generateNotFoundError() %7B%0A  return %7B%0A    title: %22Not Found%22,%0A    detail: %22Resource not found.%22%0A  %7D;%0A%7D%0A%0A// Retrieve a list of every %60test%60 resource%0Arouter.get('/tests', (req, res) =%3E %7B%0A  pg.connect(DB_URL, (err, client, done) =%3E %7B%0A    if (err) %7B%0A      res.send(500, %7B%0A        errors: %5BgenerateGenericError()%5D%0A      %7D);%0A      console.error(err);%0A      return;%0A    %7D%0A    client.query('SELECT * FROM test_table', (err, result) =%3E %7B%0A      if (err) %7B%0A        console.error(err);%0A        res.send(500, %7B%0A          errors: %5BgenerateGenericError()%5D%0A        %7D);%0A      %7D else %7B%0A        res.send(%7B%0A          data: result.rows%0A        %7D);%0A      %7D%0A    %7D);%0A  %7D);%0A%7D);%0A%0A// Return a single %60test%60 resource%0Arouter.get('/tests/:id
 ', (
@@ -1193,24 +1193,97 @@
  if (err) %7B%0A
+      res.send(500, %7B%0A        errors: %5BgenerateGenericError()%5D%0A      %7D);%0A
       consol
@@ -1325,33 +1325,33 @@
    client.query(
-'
+%60
 SELECT * FROM te
@@ -1350,33 +1350,61 @@
  FROM test_table
-'
+ WHERE id = $%7Breq.params.id%7D%60
 , (err, result) 
@@ -1474,22 +1474,210 @@
 end(
-%22Error %22 + err
+500, %7B%0A          errors: %5BgenerateGenericError()%5D%0A        %7D);%0A      %7D else %7B%0A        if (!result.rows.length) %7B%0A          res.status(404).send(%7B%0A            errors: %5BgenerateNotFoundError()%5D%0A          %7D
 );%0A 
@@ -1673,32 +1673,34 @@
       %7D);%0A      
+ 
+ 
 %7D else %7B%0A       
@@ -1684,32 +1684,34 @@
        %7D else %7B%0A
+  
         res.send
@@ -1715,21 +1715,66 @@
 end(
-result.rows);
+%7B%0A            data: result.rows%5B0%5D%0A          %7D);%0A        %7D
 %0A   
@@ -1794,16 +1794,17 @@
   %7D);%0A%7D)
+;
 %0A%0Amodule

Add route to retrieve a single test resource