{"size": 543, "ext": "js", "max_stars_repo_path": "lib/notes.js", "max_stars_repo_name": "Harabushi/harabushis-note-takerizer", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/notes.js", "max_issues_repo_name": "Harabushi/harabushis-note-takerizer", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/notes.js", "max_forks_repo_name": "Harabushi/harabushis-note-takerizer", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.625, "max_line_length": 60, "alphanum_fraction": 0.6740331492}
let notes = require('../db/db.json');
const fs = require('fs');
const path = require("path");

const getNotes = () => notes;

const createNote = function (newNote) {
  notes.push(newNote);
  saveNotes(notes);
}

const deleteNote = function (id) {
  const filteredNotes = notes.filter(note => note.id != id);
  notes = filteredNotes;
  saveNotes(filteredNotes);
}

const saveNotes = notes => 
  fs.writeFileSync(
  path.join(__dirname, '../db/db.json'),
  JSON.stringify(notes, null, 2)
);

module.exports = { createNote, deleteNote, getNotes }