Skip to content

Instantly share code, notes, and snippets.

@nerdylocks
Last active August 29, 2015 14:13
Show Gist options
  • Save nerdylocks/17e960035cfa2e25b353 to your computer and use it in GitHub Desktop.
Save nerdylocks/17e960035cfa2e25b353 to your computer and use it in GitHub Desktop.
Todo.prototype.addTask = function(date, taskName, callback){
this.model.findOne({
date: date
}, function(error, data) {
var taskId;
if (error) {
console.error('error:findOne:', error); //optional, so helpful during development. it will tell you exactly where there exception happened.
throw new Error(error); //this will make it an instance of the javascript native Error class.
}
if(!data) {
taskId = 1;
} else {
taskId = data.tasks.length + 1;
}
var newTask = new models.todoModel({
date : this.date,
tasks : [{ status: false,
taskName: taskName,
taskId : taskId
}]
});
newTask.save(function(error){
if(error) {
throw new Error(error);
}
callback(null, true);
});
});
};
Todo.prototype.todoExists = function (date, callback){
this.model.findOne({
date : date
}, function(error, data){
if(error) {
throw new Error(error);
}
if (!data) {
callback(null, false);
} else {
callback(null, true);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment