What's wrong with my Exercise Tracker?

Tell us what’s happening:
Describe your issue in detail here.
Currently stuck at third to last and second to last problem.

The questions ask me to make a GET request to /api/users/:_id/logs to retrieve a full exercise log of any user. The returned response will be the user object with a log array of all the exercises added. Each log item has the description, duration, and date properties.
Also to make sure a request to a user's log (/api/users/:_id/logs) returns an object with a count property representing the number of exercises returned.

All my results are identical to the provided demonstration. I also manually gone through the whole test with the data sent by FCC (by retrieving datasets in MongoDB labelled “fcc_test…” and run them again), all functioned perfectly fine. I can’t figure out what went wrong .

my results look like this:

{
“_id”: “610b795a92f40f00d2c644bd”,
“username”: “will199603”,
“count”: 1,
“log”: [
{
“description”: “swimming”,
“duration”: 15,
“date”: “Thu Aug 05 2021”
}
]
}

my code for the part

app.post("/api/users/:_id/exercises", bodyParser.urlencoded({ extended: false }),(req,res) => {
let id = req.params._id;
let duration = parseInt(req.body.duration,10);
let description = req.body.description;
let date;

//assign the current date if the date is not specified
if (!req.body.date) {
date = new Date().getTime().toDateString();
} else {
date = new Date(req.body.date).toDateString();
}
let update = {
description: description,
duration: duration,
date: date
}

User.findById({_id: id})
.exec((error, foundUserData) => {
if (error) {
res.send(“The ID doesn’t exist.”)
return
}
let exercisesModel = new Exercises(update);

foundUserData.log.push(exercisesModel);

foundUserData.save((err, loggedData) => {
  if (err) {
    res.send("There's an error while uploading exercises to the log")
  } else {
    
    let toBeSent = {
      username: loggedData.username,
      _id: loggedData._id,
      description: update.description,
      duration:update.duration,
      date: update.date
    }
    res.json(toBeSent)
  }
})

})
})

Your project link(s)

solution(live app): Glitch :・゚✧
code:Glitch :・゚✧

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0

Challenge: Exercise Tracker

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.