import express from 'express';
import fs from 'fs';
import path from 'path';

export default function getRoutes(tablesPath, collection) {
  let router = express.Router();
  const fileName = path.join(tablesPath, collection.name, 'config.json');
  const fileReadOptions = {
    enc: 'utf8'
  };
  let config = fs.readFileSync(fileName, fileReadOptions);
  let configObj = JSON.parse(config);

  router.get('/api/v1/' + collection.name, function(req, res) {
    collection.find({}).then(function(rows){
      res.send({rows: rows, colNames: configObj.colNames});
    }).catch(function(err) {
      res.send(err);
    });
  });

  return router;
}
@@ -445,16 +445,22 @@
 req, res
+, next
 ) %7B%0A    
@@ -595,24 +595,217 @@
 %7B%0A      
-res.send
+next(err);%0A    %7D);%0A  %7D);%0A%0A  router.post('/api/v1/' + collection.name, function(req, res, next) %7B%0A    collection.save(req.body).then(function() %7B%0A      res.end();%0A    %7D).catch(function(err) %7B%0A      next
 (err);%0A 
@@ -817,17 +817,16 @@
 ;%0A  %7D);%0A
-%0A
   return

add route to save new data