A part of mycode was working than stopped

Tell us what’s happening:
Im doing now the exercise tracking challenge , when reached the last task when it asks to :

You can add from , to and limit parameters to a /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.

I finished the limit part and when I tasted it it worked than I added the From To part but this one didn’t work the weird stuff here is when I commented the last part (From To) the first one didn’t work too I want back tapping Ctrl + Z until all the second part disappeared but still doesn’t work , and I don’t know what happened exactly

app.get("/api/users/:_id/logs", (req,res)=>{
  let id = req.params._id 
TRACKER.findById( id , 
    (error, data )=>{
        let resObj = {}
        resObj['_id'] = data.id
        resObj['username'] = data.username
        resObj['count'] = data.log.length
        resObj['log'] = data.log

        // This is the Scond part

        // if(req.query.from || req.query.to) {
            //   let fromDate = new Date(0)
            //   let toDate = new Date()
            //   if(req.query.from) {
            //     fromDate = new Date(req.query.from)
            //   }
            //   if(req.query.to){
            //     toDate = new Date(req.query.to)
            //   }

            //   data.log = data.log.filter((exerciseItem)=>{
            //     exerciseItemDate = new Date(exerciseItem.date)

            //     return exerciseItemDate.getTime() >= fromDate.getTime()
            //     && exerciseItemDate.getTime()<= toDate.getTime()
            //   })
        // }

        // This is the first one which stopped 
          data.log = data.log.slice(0,req.query.limit)

Your project link(s)

solution: https://replit.com/@smailove/boilerplate-project-exercisetracker-1

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

Update : Its working on the console.log but not in the res.json array

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