changes
This commit is contained in:
@@ -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}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user