Back End Development and APIs Projects - Exercise Tracker

I’m struggling to pass the last test: When console logging out the found exercises, I am getting an empty array. however the exercise query object that I pass into the Model.find() method looks okay to me. I am using TypeScript. Looking at getExerciseLogById function and fetchExerciseLogs function .

Any help much appreciated.

Your project link(s)
solution: boilerplate-project-exercisetracker - Replit

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

If you inspect the request/response in the browser dev tools you can see your POST is throwing.

Log out the error in the catch inside createAndSaveExerciseToDb.

As an aside, unless you log or send the error the try/catch is not going to be very useful when developing.

Thank you - I logged out the error as you suggested and I am not saving the exercises to the db - so I couldn’t retrieve them.

So I have created an exercise model to save to the db however this now fails on both the last test and this test - " The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added."

Help appreciated. Here is my replit link : boilerplate-project-exercisetracker - Replit

Okay so this test is now passing: " The response returned from POST /api/users/:_id/exercises will be the user object with the exercise fields added."

I kept my existing Exercise Model to save the posted exercise details to the db. I then used these details (duration, date and description) to update the properties on the User object. However I am still not passing the last test.

On the log response object, I have checked that:

  • the date queries filter correctly
  • the limit query responds with an array of only that number of exercises
  • there are no typos
  • the data types of the values are correct

Any help much appreciated boilerplate-project-exercisetracker - Replit

Request URL:

Response: {
    "username": "no username found",
    "count": 0,
    "_id": "6526dfe18e4a35d100fef65b",
    "log": "no logs found"

I didn’t test it but I think your dates in the schema have to be of type Date for the code you have to work (the to/from part of the query object). It definitely doesn’t seem like your ExerciseModel.find is returning what it should.

Finally managed to sort the issues and got all tests passing.

Initially I changed the date format from toDateString() to toUTCString() however it appears Mongoose doesn’t compare dates correctly in this format.

Last test passed with ensuring dates were stored in database using toISOString() and only using the toDateString() format when sending the response back to the user in the exercise/logs objects.

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