Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
I’ve been trying since last 3 days and unable to pass the last 2 taste cases.
Can anybody help me out ?

Your project link(s)

solution: boilerplate-project-exercisetracker - Nix (beta) Repl - Replit

Your browser information:

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

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

I forked and ran your code and logged the response from your GET log route and got the following output:

{
  "_id": "62fc5d0ca5d61018e53aa313",
  "username": "fcc_test_16607060603",
  "count": 2,
  "log": [
    {
      "date": "Wed Jan 03 1990",
      "duration": 60,
      "description": "test",
      "_id": "62fc5d0ca5d61018e53aa317"
    }
  ],
  "__v": 0
}

which is correct except for count, which your code does not update when from, to, or limit is set. I would need to look at the source for the tests to see if the log test checks the count but it’s either that or it’s the often mentioned timezone offset problem that’s keeping you from passing the penultimate test. Everything else was passing.

1 Like

Your code from Replit for the GET request "/api/users/:_id/logs":

     if (from || to) {
        from = Date.parse(new Date(from));
        to = Date.parse(new Date(to));
        // console.log(from, to);
        // console.log(logs);
        logs = logs.filter((log) => {
          const temp = Date.parse(new Date(log.date));
          // console.log(temp);
          // console.log("log " + (temp >= from && temp <= to));
          return temp >= from && temp <= to;
        });
        console.log(logs);
      }

You are not getting correct output because of the inadequate checking of the from and to date query string parameters. You have only one check, if (from || to) { .... What happens when from is not provided (and its value is undefined)? The result is not correct in the response.

Your parameter validation must be complete for all cases of non-existence / existence of the from and / or to.