{"size": 1210, "ext": "js", "max_stars_repo_path": "app/controllers/noteBookController.js", "max_stars_repo_name": "lutakyn/expressbackend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/controllers/noteBookController.js", "max_issues_repo_name": "lutakyn/expressbackend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/controllers/noteBookController.js", "max_forks_repo_name": "lutakyn/expressbackend", "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": 18.90625, "max_line_length": 69, "alphanum_fraction": 0.4553719008}
import mongoose from 'mongoose'; 
import note from '../models/notebookModel.js';

exports.getNote = (req, res) => {
    note.findById(req.params.noteId, (err, note) => {
        if (err) {
            res.send(err);
        }

        res.json(note);
    });
};


exports.getAllNotes = (req, res) => {
    note.find({}, (err, notes) => {
        if (err) {
            res.send(err);
        }

        res.json(notes);
    });
};

exports.createNote = (req, res) => {
    const newNote = new note(req.body);

    newNote.save((err, note) => {
        if (err) {
            res.send(err);
        }

        res.json(note);
    });
};

exports.updateNote = (req, res) => {
    console.log("req",req.params.noteId)
    note.findOneAndUpdate({
        _id: req.params.noteId
        
    }, req.body,
        (err, note) => {
            if (err) {
                res.send(err);
            }

            res.json(note);
        });
};

exports.deleteNote = (req, res) => {
    note.remove({
        _id: req.params.noteId
    }, (err) => {
        if (err) {
            res.send(err);
        }

        res.json({
            message: `note ${req.params.noteId} successfully deleted`
        });
    });
};