# Back End Development and APIs Projects - Exercise Tracker

**URL:** <https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 23, 2023, 6:47am UTC](https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928 "2023-09-23T06:47:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![farisbrandone](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/farisbrandone/32/134214_2.png) [@farisbrandone](https://forum.freecodecamp.org/u/farisbrandone)\
**Post date:** [September 23, 2023, 6:47am UTC](https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928/1 "2023-09-23T06:47:12Z")

</div>

**Tell us what’s happening:**  
Hello everyone, please I need help.  
when i test my code the last condition is not respected whatever i face  
here is the condition :  
/**/  
You can add `from` , `to` and `limit` parameters to a `GET /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.  
/**/

below is the part of the code that handles this condition:

ci-dessous la partie du code gérant cette condition:  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

```auto
app.get("/api/users/:_id/logs", async (req, res) => {
  const id = req.params._id
  const {from,to, limit}=req.query
  console.log( {from,to, limit})
  const fromDate=new Date(from)
  const toDate= new Date(to);
  const limitDate=Number(limit)
  
  
  try {
   
    const logResults = await Log.findOne({
      id
    })
    let logTable=[]
    let i=0
    let j=1
    if(fromDate.toString()!=="Invalid Date" && toDate.toString()!=="Invalid Date" && limitDate && Boolean(logResults)){
    let fromValue=fromDate.valueOf()
    let toValue=toDate.valueOf()

      while (i<logResults.log.length && j<=limitDate){
        
         const logElt=new Date(logResults.log[i].date)

         if (logElt.valueOf()>=fromValue && logElt.valueOf()<=toValue){
          logTable.push(logResults.log[i])
          j=j+1
         }
         i=i+1
  
      } 
      console.log("first",{
        _id: logResults.id,
        username: logResults.username,
        from:fromDate.toDateString(),
        to:toDate.toDateString(),
        count: limitDate,
        log:logTable
      })
      res.json({
        _id: logResults.id,
        username: logResults.username,
        from:fromDate.toDateString(),
        to:toDate.toDateString(),
        count: limitDate,
        log:logTable
      })
  
    }else if(fromDate.toString()!=="Invalid Date" && toDate.toString()!=="Invalid Date" && !limit && Boolean(logResults)){
      let fromValue=fromDate.valueOf()
      let toValue=toDate.valueOf()
  
        while (i<logResults.log.length){
          
           const logElt=new Date(logResults.log[i].date)
  
           if (logElt.valueOf()>=fromValue && logElt.valueOf()<=toValue){
            logTable.push(logResults.log[i])
            j=j+1
           }
           i=i+1
    
        } 
        console.log("second",{
          _id: logResults.id,
          username: logResults.username,
          from:fromDate.toDateString(),
          to:toDate.toDateString(),
          count: limitDate,
          log:logTable
        })
        res.json({
          _id: logResults.id,
          username: logResults.username,
          from:fromDate.toDateString(),
          to:toDate.toDateString(),
          count:j-1,
          log:logTable
        })
    
      }else if(fromDate.toString()!=="Invalid Date" && !to && limitDate && Boolean(logResults)){
        let fromValue=fromDate.valueOf()
        
    
          while (i<logResults.log.length && j<=limitDate){
            
             const logElt=new Date(logResults.log[i].date)
    
             if (logElt.valueOf()>=fromValue ){
              logTable.push(logResults.log[i])
              j=j+1
             }
             i=i+1
      
          } 
          console.log("third",{
            _id: logResults.id,
            username: logResults.username,
            from:fromDate.toDateString(),
            to:toDate.toDateString(),
            count: limitDate,
            log:logTable
          })
          res.json({
            _id: logResults.id,
            username: logResults.username,
            from:fromDate.toDateString(),
            count:j-1,
            log:logTable
          })
      
        }else if(toDate.toString()!=="Invalid Date" && !from && limitDate && Boolean(logResults)){
          let toValue=toDate.valueOf()
          
      
            while (i<logResults.log.length && j<=limitDate){
              
               const logElt=new Date(logResults.log[i].date)
      
               if (logElt.valueOf()<=toValue ){
                logTable.push(logResults.log[i])
                j=j+1
               }
               i=i+1
        
            } 
            console.log("fourth",{
              _id: logResults.id,
              username: logResults.username,
              from:fromDate.toDateString(),
              to:toDate.toDateString(),
              count: limitDate,
              log:logTable
            })
            res.json({
              _id: logResults.id,
              username: logResults.username,
              to:toDate.toDateString(),
              count:j-1,
              log:logTable
            })
        
          }else if(fromDate.toString()!=="Invalid Date" && !to && !limit && Boolean(logResults)){
            let fromValue=fromDate.valueOf()
            
        
              while (i<logResults.log.length){
                
                 const logElt=new Date(logResults.log[i].date)
        
                 if (logElt.valueOf()>=fromValue ){
                  logTable.push(logResults.log[i])
                  j=j+1
                 }
                 i=i+1
          
              } 
              console.log("fith",{
                _id: logResults.id,
                username: logResults.username,
                from:fromDate.toDateString(),
                to:toDate.toDateString(),
                count: limitDate,
                log:logTable
              })
              res.json({
                _id: logResults.id,
                username: logResults.username,
                from:fromDate.toDateString(),
                count:j-1,
                log:logTable
              })
          
            }else if(toDate.toString()!=="Invalid Date" && !from && !limit && Boolean(logResults)){
              let toValue=toDate.valueOf()
              
          
                while (i<logResults.log.length){
                  
                   const logElt=new Date(logResults.log[i].date)
          
                   if (logElt.valueOf()<=toValue ){
                    logTable.push(logResults.log[i])
                    j=j+1
                   }
                   i=i+1
            
                } 
                console.log("sixth",{
                  _id: logResults.id,
                  username: logResults.username,
                  from:fromDate.toDateString(),
                  to:toDate.toDateString(),
                  count: limitDate,
                  log:logTable
                })
                res.json({
                  _id: logResults.id,
                  username: logResults.username,
                  to:fromDate.toDateString(),
                  count:j-1,
                  log:logTable
                })
            
              }else if(!from && !to && limitDate && Boolean(logResults)){
        
                  while (i<limitDate && i<logResults.log.length){
                    
                     const logElt=new Date(logResults.log[i].date)
                      logTable.push(logResults.log[i])
                     i=i+1
                  } 
                  console.log("seventh",{
                    _id: logResults.id,
                    username: logResults.username,
                    from:fromDate.toDateString(),
                    to:toDate.toDateString(),
                    count: limitDate,
                    log:logTable
                  })
                  res.json({
                    _id: logResults.id,
                    username: logResults.username,
                    from:fromDate.toDateString(),
                    count:i,
                    log:logTable
                  })
              
                }
    
    else {

      res.json({
        username: logResults.username,
        count: logResults.count,
        _id: logResults.id,
        log: logResults.log
      })
    }
    

  } catch (err) {
    res.send(err)
  }

})

```

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

**Your project link(s)**

solution: [http://localhost:3000](http://localhost:3000)

**Your browser information:**

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

**Challenge:** Back End Development and APIs Projects - Exercise Tracker

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/exercise-tracker)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![lasjorg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lasjorg/32/280761_2.png) [@lasjorg](https://forum.freecodecamp.org/u/lasjorg)\
**Post date:** [September 23, 2023, 6:37pm UTC](https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928/2 "2023-09-23T18:37:44Z")

</div>

Please post a repo, or Replit/Glitch with your code.

* * *

I didn’t test or read much of the code but you should be able to greatly simplify it. There is no reason why this handler should have ~250 lines of code.

---

<div class="post-metadata">

**Author:** ![farisbrandone](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/farisbrandone/32/134214_2.png) [@farisbrandone](https://forum.freecodecamp.org/u/farisbrandone)\
**Post date:** [September 24, 2023, 1:54am UTC](https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928/3 "2023-09-24T01:54:01Z")

</div>

here is the url of my git repository below.  
i’ve actually improved the code. everything works normally locally but going to the test i’ve got this last condition blocking me.  
i really need help please  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* in the image below the results of the test\*\*\*\*\*\*\*\*\*\*\*\*/

 ![testbackend4](https://global.discourse-cdn.com/freecodecamp/original/4X/0/5/5/0558fe682d945b967628b867d47efc74f7855ea8.png)

/_ **url of the git repository:** __ **/** _

> **[GitHub - farisbrandone/project4backendfreecodecamp: quatrième project backend...](https://github.com/farisbrandone/project4backendfreecodecamp)**
>
> quatrième project backend de freecodecamp. Contribute to farisbrandone/project4backendfreecodecamp development by creating an account on GitHub.

   
_ **/** _\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

---

<div class="post-metadata">

**Author:** ![mostafa-hesham](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mostafa-hesham/32/336073_2.png) [@mostafa-hesham](https://forum.freecodecamp.org/u/mostafa-hesham)\
**Post date:** [October 1, 2023, 9:45pm UTC](https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928/4 "2023-10-01T21:45:18Z")

</div>

![image](https://global.discourse-cdn.com/freecodecamp/original/4X/3/1/4/3147e1ecb84b90c13c9f53c7e35ed620b1abb827.png)  
stuck at this test case while I tested it in Postman I got the expected output with the right data types.  
code : [boilerplate-project-exercisetracker - Replit](https://replit.com/@MainUseless/boilerplate-project-exercisetracker?v=1)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [April 1, 2024, 9:46am UTC](https://forum.freecodecamp.org/t/back-end-development-and-apis-projects-exercise-tracker/639928/5 "2024-04-01T09:46:12Z")

</div>

Closed on April 1, 2024, 9:46am UTC

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