I am stacked on ** You can make a GET
request to /api/users/:_id/logs
to retrieve a full exercise log of any user.** when i test the logs, it returns me all the users, but cant pass the tests. here i share my app link.exercise-tracker it is working well.But i didnt understand why cant pass. Also i want to share my code that returns the logs
app.get('/api/users/:_id/logs', (req, res) => {
const id = req.params._id;
User.findById(id, (err, data) => {
if (err) return console.log(err);
res.json({
_id: id,
username: data.username,
count: data.__v,
log: data.log.map((e) => {
return {
description: e.description,
duration: e.duration,
date: new Date(e.date).toDateString(),
};
}),
});
});
});
also this is how i add new exercises
app.post('/api/users/:id/exercises', (req, res) => {
const id = req.params.id;
const description = req.body.description;
const duration = req.body.duration;
const date = req.body.date;
console.log(duration);
console.log(id);
User.findById(id, (err, user) => {
console.log(user);
if (err) return console.log(err);
// user.count = user.count + 1;
user.log.push({
description: description,
duration: duration,
date: new Date(date).toDateString(),
});
user.save((err, data) => {
if (err) return console.log(err);
res.json({
_id: id,
username: data.username,
date: new Date(date).toDateString(),
duration: JSON.parse(duration),
description: description,
});
});
});
});
also github link related [github link]
(https://github.com/sayinmehmet47/boilerplate-project-exercisetracker)
also this is how i add the execises to mongodb