// Controllers contain the functions and businnes logics of our Express JS application // Allows us to use the contents of  the "Task.js" file in the "models" folder const Task = require("../models/Task"); // Controller function for getting all the tasks module.exports.gettasks = () => { return Task.find({}).then(result => { // the "return" statement, returns the result of the Mongoose method "find" back to the "taskRoute.js" file which invoke this function return result; }); } module.exports.createTask = (requestBody) => { let newTask = new task({ name: requestBody.name }); return newTask.save().then((task,error) =>{ if(error){ return false; }else{ return task; } }); } module.exports.deleteTask = (taskId)=>{ return Task.findByIdAndRemove(taskId).then((removedTask,error)=>{ if (error){ console.log(error); return falsel }else{ return removedTask; } }) }