Exercise Tracker Last Test Failing

How to debug is easy. Log all the inputs and responses for the misbehaving route:

app.get("/api/users/:_id/logs", (req,res)=>{
  console.log(req.body);
  console.log(req.params);
  console.log(req.query);
  
  if(req.params._id.match(/^[0-9a-fA-F]{24}$/)){
    Athleat.findById(req.params._id,(err, person)=>{
      if (err) return console.error(err);
      if (!person) return res.json({error: "id not found"});
      let sortedLog = person.log.sort(
        (objectOne, objectTwo) => {
           return new Date(objectTwo.date).getTime() - new Date(objectOne.date).getTime();
        });
      if (new Date(req.query.from)!="Invalid Date"){
          const minDate = new Date(req.query.from).getTime();
          sortedLog = sortedLog.slice(sortedLog.findIndex((object)=>
          minDate <= new Date(object.date).getTime()),)
        }
      if (new Date(req.query.to)!="Invalid Date"){
          const maxDate = new Date(req.query.to).getTime();
          sortedLog = sortedLog.slice(0,sortedLog.findIndex((object)=>
          new Date(object.date).getTime() >= maxDate)+1)
        }
      if (req.query.limit && parseInt(req.query.limit)>0){
        sortedLog = sortedLog.slice(0, parseInt(req.query.limit))
      }
      
      console.log({_id:person._id, username:person.username, count: sortedLog.length, log: sortedLog})
      return res.json({_id:person._id, username:person.username, count: sortedLog.length, log: sortedLog})
        
    });
  }
  else {
   console.log({error: "invalid id"})
   return res.json({error: "invalid id"})
  }
 
});

Or in other words, log req.body, req.params, and req.query at the beginning of your route and then log every response the route will send by duplicating a return res.json(...) with a console.log(...). This generates with the fCC tests

}
{ _id: '612d75d6cd47bb41d7a0b5ae' }
{}
{
  _id: new ObjectId("612d75d6cd47bb41d7a0b5ae"),
  username: 'fcc_test_16303692386',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 2021-08-31T00:00:00.000Z,
      _id: new ObjectId("612d75d6cd47bb41d7a0b5b1")
    }
  ]
}
{}
{ _id: '612d75d7cd47bb41d7a0b5b5' }
{}
{
  _id: new ObjectId("612d75d7cd47bb41d7a0b5b5"),
  username: 'fcc_test_16303692390',
  count: 1,
  log: [
    {
      description: 'test',
      duration: 60,
      date: 2021-08-31T00:00:00.000Z,
      _id: new ObjectId("612d75d7cd47bb41d7a0b5b8")
    }
  ]
}
{}
{ _id: '612d75d7cd47bb41d7a0b5bc' }
{ from: '1989-12-31', to: '1990-01-03' }
{
  _id: new ObjectId("612d75d7cd47bb41d7a0b5bc"),
  username: 'fcc_test_16303692395',
  count: 0,
  log: []
}

Pay attention to the dates, since they are all from when the tests run and not from when the exercise should be recorded, which means the filtered log is not returning any results and the test expects some results.