NotesHelper.js

function getNotesByDateRange(DB, req, res) {
    var username = req.decoded.username;
    var start    = new Date(req.body.start).getTime();
    var end      = new Date(req.body.end).getTime();
   
    var query = {
        'user.username': username,
        'timestamp': {
            '$gte': start,
            '$lte': end
        },
        'type': 'NOTE'
    };

    var matches = [];

    function done(err, doc) {   
        if (doc != null) {
            matches.push(doc)
        } else {
            res.json({"message": "show me the notes", "documents": matches});
        }
    }

    DB.TemplateClln.find(query, { _id: 0, data: 1, timestamp: 1}).each(done);
}


module.exports = {
    getNotesByDateRange
};