Tell us what’s happening:
Describe your issue in detail here.
Your project link(s)
The response returned from POST /api/users/:_id/exercises
will be the user object with the exercise fields added.
…
here response is correct but it shows error, I don’t know why, below is my response
{
- “_id”: “6353ab8ef47f5ea548cf40dd”,
- “username”: “RahulkumarRV”,
- “date”: “Sat Oct 22 2022”,
- “duration”: 12,
- “description”: “hum num”
}
any one know why this happens
…
solution: http://localhost:3000
githubLink: GitHub - RahulkumarRV/boilerplate-project-exercisetracker-1: A boilerplate for a freeCodeCamp project.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Challenge: Back End Development and APIs Projects - Exercise Tracker
Link to the challenge:
I will run it locally in a moment and get back to you.
I’ve run it locally and used one of the users.
The request was complete without an error.
What sort of error have you had?
I think the issue in your project it is this endpoint:
/api/users/:_id/logs
In the example it looks that it needs 3 query string values
GET /api/users/:_id/logs?[from][&to][&limit]
The logs endpoint !
from to and limit
You can add from
, to
and limit
parameters to a GET /api/users/:_id/logs
request to retrieve part of the log of any user. from
and to
are dates in yyyy-mm-dd
format. limit
is an integer of how many logs to send back.
That is missing from your code
app.get("/api/users/:_id/logs", (req, res) => {
const id = req.params._id;
let {description, date, duration} = req.body;
if(date === ''){
date = new Date();
}
UserModel.findById(id, (err, data) => {
if(err) res.json({
error : err
});
const logs = data.log.map(recode => {
return {description : recode.description,
duration : recode.duration,
date : recode.date}
})
res.json({
_id: data.id,
username: data.username,
count: data.log.length,
log: logs
});
});
});
We really need a link to a repl (like on repl.it) to fork and run the code to produce the errors.
However, you should be able to log the route inputs to and outputs from the POST exercises and GET logs routes to help diagnose the problem.