{"size": 839, "ext": "js", "max_stars_repo_path": "routes/apiRoutes.js", "max_stars_repo_name": "mlfiii/NoteTaker", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "routes/apiRoutes.js", "max_issues_repo_name": "mlfiii/NoteTaker", "max_issues_repo_issues_event_min_datetime": "2021-05-11T08:57:15.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-11T08:57:15.000Z", "max_forks_repo_path": "routes/apiRoutes.js", "max_forks_repo_name": "mlfiii/NoteTaker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 19.0681818182, "max_line_length": 78, "alphanum_fraction": 0.6078665077}
var tableData = require("../db/tableData");
const fs = require("fs");


var dataObj = {};

// console.log("tabledata:", tableData);
//Routes
module.exports = function (app) {

  //Gets
  app.get("/api/notes", function (req, res) {
    res.json(tableData);
    // console.log(tableData.length)
    // console.log(tableData);

  });

  //Posts
  app.post("/api/notes", function (req, res) {

    tableData.push(req.body);
    fs.writeFileSync(__dirname + "/../db/db.json", JSON.stringify(tableData));
    res.json(true);

  });

  //Delete

  app.delete("/api/notes/:note", function (req, res) {

    // console.log(req.params.note)
    let id = req.params.note;
    tableData = tableData.filter(data => data.id !== id)
    fs.writeFileSync(__dirname + "/../db/db.json", JSON.stringify(tableData));
    res.json({ ok: true });


  });
};



