Cannot pass the last task of a challenge Exercise Tracker

Tell us what’s happening:

I am going through a Exercise Tracker challenge and I am not able to pass the last task.
However I added the required parameters and able to retrieve part of the log using them.
All the other task done and accepted so I assume problem somewhere in this last part.
Would appreciate any help, Thank you!

My code

app.get("/api/users/:_id/logs?",async function (req,res){

let typedId = req.params._id
const {from,to,limit} = req.query 
let log = [];

try{
let foundLog = await User.findOne({_id:typedId})
if(foundLog){

let foundExeLogs = await Exe.find({key:foundLog._id},{ _id: 0 ,key:0,__v: 0}).lean().exec();
logs = [...foundExeLogs]

// CODE FOR THE LAST TASK BELOW
if(from && to){

  let newLogs = await logs.filter(foundLog =>
   new Date(foundLog.date).getTime() >= new Date(from).getTime() &&
   new Date(foundLog.date).getTime() <= new Date(to).getTime()
  )
if(limit){
newLogs = newLogs.slice(0,limit)
}
  res.json({
    _id:foundLog._id,
    username:foundLog.username,
    from: new Date(from).toDateString(),
    to: new Date(to).toDateString(),
    count:newLogs.length,
    log:newLogs 
  })

}else{
 // CODE FOR THE LAST TASK ABOVE 

  res.json({
    _id:foundLog._id,
    username:foundLog.username,
    count:logs.length,
    log:logs
  })
}
}

}catch (err) {
      console.error(err)
      res.status(500).json("Server Error")
    }

})

Your project link(s)
solution: https://replit.com/@ogdruggahat/boilerplate-project-exercisetracker-2

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

I changed the code a bit, now I am able to get logs using just from or to, but its still not passing the last test.

Updated Code

let typedFrom;
let typedTo;
if(from || to){
  if(from){
    typedFrom = new Date(from).getTime()
    logs = await logs.filter(foundLog => 
    new Date(foundLog.date).getTime() >= typedFrom)
    typedFrom = new Date(from).toDateString()
  }
  if(to){
    typedTo = new Date(to).getTime()
    logs = await logs.filter(foundLog =>
   new Date(foundLog.date).getTime() <= typedTo)
   typedTo = new Date(to).toDateString()
  }
  if(from && to){
typedFrom = new Date(from).getTime()
typedTo = new Date(to).getTime()
  logs = await logs.filter(foundLog =>
   new Date(foundLog.date).getTime() >= typedFrom &&
   new Date(foundLog.date).getTime() <= typedTo
  )
  typedFrom = new Date(from).toDateString()
  typedTo = new Date(to).toDateString()
  }
if(limit){
logs = logs.slice(0,limit)
}

  res.json({
    _id:foundLog._id,
    username:foundLog.username,
    from: typedFrom,
    to: typedTo,
    count:logs.length,
    log:logs 
  })

}

Any help will be highly appreciated !

I manage to pass the test, in my case the issue was that I was checking for the “limit” property only when “from” or “to” property was used.

I found the issue by using log with responses as suggested here:

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