Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:


I finished my exercises-tracker project, but cant pass the tests for /api/users/:_id/logs, the response have everything it needs to. I’ll leave a replit link below , if someone could help me out here, idk if logs should come from mongoose model also and be saved in mongodb. Filtering with dates and limiting results is present, test just shows “Test timed out”, because of previous tests failed I assume.

exercise-tracker Replit URL

Your project link(s)

solution: boilerplate-project-exercisetracker - Replit

Your browser information:

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

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

Something isn’t working. I just visited your site and tried to use the main form to create a new user and it isn’t redirecting me or giving me any feedback.

Log out inside the /api/users/:_id/exercises route. Do you see an issue with one of the conditions?

Sorry, Mongo Atlas stuck sometimes, says ip is not whitelisted and it is set to allow access from every ip.

Thanks for suggestion, Im making mongoose model for exercise with date key and value type of Date, so I could use filtering later in logs api, for gte and lte. The instruction says that responses should have type of Date formated with toDateString method, which I did for every response in exercise api and logs api.

Exercise api response:
{“username”:“cirko”,“description”:“Press”,“duration”:15,“date”:“Wed Nov 30 2022”,“_id”:“6387d222b6c19c88ce904715”}

Logs api response:
{“username”:“cirko”,“count”:5,“_id”:“6387d222b6c19c88ce904715”,“log”:[{“description”:“Pushups”,“duration”:15,“date”:“Wed Nov 30 2022”},{“description”:“Pullups”,“duration”:30,“date”:“Thu Jan 01 2015”},{“description”:“Walking”,“duration”:45,“date”:“Mon Jan 01 2018”},{“description”:“Sleeping”,“duration”:500,“date”:“Fri Jan 01 2010”},{“description”:“Press”,“duration”:15,“date”:“Wed Nov 30 2022”}]}

Did you at least log it out as I said to? Put in a log and submit.

Steps I used:

  1. Open the network tab in the browser and submit.

  2. Look at the log responses, the count is 0 and the array is empty.

  3. Look at the exercise response above the first log response. It is giving back an incorrect response which is the issue.

  4. Log out inside the /api/users/:_id/exercises route handler, it is not an empty string but what?

Response from ‘api/users/63887fdd272e04ca6692e9e7/logs’:
{“username”:“cirko”,“count”:1,“_id”:“63887fdd272e04ca6692e9e7”,“log”:[{“description”:“Pushups”,“duration”:15,“date”:“Thu Dec 01 2022”}]}

  1. The count is 0 when there’s no exercises added, yes.

  2. image
    Response from ‘api/users/63887fdd272e04ca6692e9e7/exercises’ route:
    {“username”:“cirko”,“description”:“Pushups”,“duration”:15,“date”:“Thu Dec 01 2022”,“_id”:“63887fdd272e04ca6692e9e7”}

  3. const date in ‘/api/users/:_id/exercises’ route:
    Console log of date const in ‘/api/users/:_id/exercises’ route:
    (data saved in mongodb for exercise model)

Yup, saw it.
Now I made date in exercises api like this:

Thanks for your help, just need to pass the tests now, managed to tick all of them except the last one, it said “Test timed out”.

When I initially forked your project and fixed the date issue it passed all the tests. Now I see this error.

TypeError: Cannot set properties of undefined (setting ‘$gte’)

Before you had this:

filter = { userId: id, date: { $gte: from } }

Now you have this:['$gte'] = from;

You can’t do that.

const obj = {}
obj.first.second = 'test'
// Uncaught TypeError: Cannot set properties of undefined (setting 'second')

When I fix that (for both to and from) it passes all the tests.

Yes, the last test timed out with previous code, you’re telling me about, so I experimented a little bit, I know I can’t do that, saw it myself :grin:

Will try again with the previous code, hope it doesn’t time out.

Thanks for the help, really, appreciate you.

Turns out it was a problem to run the test from my work pc, cuz it uses proxies and stuff… Passed all the tests when I ran them on my phone, thanks for all the help, this topic can be closed now.

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