This commit is contained in:
2026-03-31 18:30:49 +08:00
parent bad112803a
commit d777d3065d
557 changed files with 119933 additions and 2 deletions

View File

@@ -1,3 +1,6 @@
const { MongoClient, ServerApiVersion } = require('mongodb');
const uri = "mongodb+srv://<db_username>:<db_password>@cluster0.dombm2a.mongodb.net/?appName=Cluster0";
const express = require('express');
const cors = require('cors');
@@ -57,6 +60,32 @@ app.get("/api/tasks", async (req, res) => {
}
});
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);
res.status(201).json(newTask);
}
catch (error) {
console.error(`Error: ${error}`)
res.status(500).json({ message: "Error creating task" })
}
});
app.listen(port, () => {
console.log(`To Do App listening on port ${port}`);
});