// const { MongoClient, ServerApiVersion } = require('mongodb'); // const uri = 'mongodb+srv://ugochikay_db_user:bt06DpE6QZqLHZ1x>@cluster0.aqxmamw.mongodb.net/?appName=Cluster0'; //Dependancies const express = require("express"); const cors = require("cors"); const port = 3000; const app = express(); //Middleware setup app.use(express.json()); app.use(cors("*")); //change //API routes app.get("/get/example", async (req, res) =>{ res.send("Hello this is a Message from Backend") }) const tasks = [ { id: 1, completed: false, title:"Wash car", decription: "Make sure I have washed the car well", dueDate: "14/03/2026", dateCreated: new Date(Date.now()).toLocaleString() }, { id: 2, completed: true, title: "Audit Report", description: "The Audit Report must be ready by due date", duedate: "16/03/2026", dateCreated: new Date(Date.now()).toLocaleString() }, { id: 3, completed: true, title: "Performance Report", description: "The Performance Report must be ready by due date", duedate: "16/03/2026", dateCreated: new Date(Date.now()).toLocaleString() }, ]; //Get all Tasks app.get("/api/tasks", async (req, res) => { try { res.json(tasks);//Successful, responds to frontend with json list items } catch (error){ console.error(`Error: ${error}`);//Spits out the message in server console res.status(500).json({message:"Error grabbing tasks!"});//Responds with error 500 and a JSON mess } }) // Create a new Task and add it to the tasks array/list app.post("/api/tasks/todo", async (req, res) => { try{ const {title, description, dueDate} = req.body; const newTask = { id: tasks.length + 1, completed: false, title: title, description: description, dueDate: dueDate, dateCreated: new Date(Date.now()).toLocaleDateString("en-AU") }; tasks.push(newTask); res.json(newTask); } catch (error){ console.error(`ERROR: ${error}`); res.status(500).json({message: "Error creating the task"}); } }); //App startup app.listen(port, () => { console.log(`To Do App listening on port ${port}`); });