diff --git a/src/Controller.js b/src/Controller.js index 6c18c82a2a941b315008e4076d6f5140acdcb962..d546e4fdc8a1b0f3ff986b79d134fa4e27b1b551 100644 --- a/src/Controller.js +++ b/src/Controller.js @@ -15,7 +15,7 @@ async function fetchTodoElements(){ fetchTodoElements(); //Used by the button next to the textbox -todoForm.addEventListener('Submit', function(e){ +todoForm.addEventListener('submit', function(e){ e.preventDefault(); addTodoElement(); }) @@ -23,7 +23,7 @@ todoForm.addEventListener('Submit', function(e){ //Method updates the list in the HTML doc async function updateList(){ todoList.innerHTML = ""; - todoElements.forEach(()=>{ + todoElements.forEach((todo, index)=>{ const todoElement = createItem(todo, index); todoList.append(todoElement); }) @@ -56,7 +56,7 @@ async function updateStatus(index, isChecked){ newStatus = "open"; } - await fetch(`${url}$/${todoId}`, { + await fetch(`${url}/${todoId}`, { method: "PATCH", headers: {"Content-Type": "application/json"}, body: JSON.stringify({status: newStatus}), diff --git a/src/DatabaseController.js b/src/DatabaseController.js index ed8653a6885de93e773666bf2ea8e7abb5593221..3f83bd5895ffcbf1800f1f6c85dc78420189d2f6 100644 --- a/src/DatabaseController.js +++ b/src/DatabaseController.js @@ -8,7 +8,7 @@ const PORT = process.env.PORT || 5000; app.use(cors()); app.use(express.json()); -const uri = "mongodb+srv://famboupeabbas:dbCloudComputing@todocloudcomputing.pcms2.mongodb.net/?retryWrites=true&w=majority&appName=todoCloudComputing"; +const uri = "mongodb://localhost:27017/CloudComputing"; //Method to create database connection mongoose.connect(uri) @@ -18,13 +18,13 @@ mongoose.connect(uri) process.exit(1);}); const Template = new mongoose.Schema({ - task: String, - status: {type: string, default: "open"} + text: String, + status: {type: String, default: "open"} }); -const todoTemplate = mongoose.model("Todo", Template); +const todoTemplate = mongoose.model("todos", Template); -app.listen(PORT, () => console.log(`Server was started on port ${PORT}`)); +app.listen(PORT, () => console.log(`Server was started on port ${PORT}`)); //Method to fetch all the elements from the database app.get("/todos", async (req, res) => { @@ -34,7 +34,7 @@ app.get("/todos", async (req, res) => { //Method to add an element to the database app.post("/todos", async (req, res) => { - const addedTodo = new Template({text: req.body.text, status: "open"}); + const addedTodo = new todoTemplate({text: req.body.text, status: "open"}); await addedTodo.save(); res.json(addedTodo); });