Last active
August 29, 2015 14:13
-
-
Save nerdylocks/17e960035cfa2e25b353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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