When I access the server with postman, I get an error like a id not found or some thing like this.
Here is my code on get-routs.js :
<div class="main">
<ul>${tasks
.map((item) => {
return ` <li data-id="${item.Id}">
<span>
<lable>${item.Title}</lable>
<span class="${item.complited ? "com" : "uncom"}">${
item.complited ? "complited" : "in progress"
}</span>
<button class="toggle-btn">toggle</button>
<button class="edit-btn" >edit</button>
<button class="delete-btn">delete</button>
</span>
</li>`;
})
.join("")}
</ul>
and here its post-route.js :
router.post("/toggle-task", (req, res) => {
if (req.body.Id) {
const task = Task.getTaskById(req.body.Id);
console.log(req.body.Id);
if (task) {
task.complited = !task.complited;
task.save();
res.send("1");
} else {
res.status(404).send("<h1> task not foundd</h1>");
}
} else {
res.status(400).send("error");
}
});
export default router;
Despite in json file id number 2 exists post man gives error or doesn’t work
and here is my database :
[
{
"id": 1,
"title": "Learn js",
"complited": false
},
{
"id": 2,
"title": "Nodejs",
"complited": false
},
{
"id": 3,
"title": "SQl",
"complited": true
}
]