I cannot pass the last test. I see the correct things according to the spec:
but am not passing the last test:
// running tests
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.
// tests completed
I have tried all sorts of things and have looked at lots of other threads on the same subject and tried various suggestions but cannot find anything that works. I am using Cluster0 from Mongo Atlas with a Ireland (eu-west-1) region.
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0
Challenge: Back End Development and APIs Projects - Exercise Tracker
Link to the challenge:
I cannot pass the last test:
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.
I have tried all sorts of things, such as:
having the date in the exercise schema being a date type,
using toISOString() and toUTCString()
changing my computers timezone to every timezone and running the test in each timezone,
trying different ways of getting rid of any time element to avoid time differences between my location
and wherever the tests are run from
I have tried using Chrome, Edge and am currently using Firefox
I have tried writing my program in Visual Studio Code
all to no avail
My current code has the date in the exercise schema as a Number type and storing the data (when posting) as yyyymmdd (eg 20221021) and then turning the from and to parameters into the same format for comparison.
I have been trying to pass this for the last 2 weeks
I would really appreciate any help in progressing
(I asked this under Backend Development but the only help suggested timezone issues which I have tried as mentioned above - I am asking this in this subforum in case someone here has any ideas)
You’re not logging the route inputs and outputs. You need to do that from your POST exercise and GET logs routes. And you need to log the output before every single res.json(...) in the GET logs route because there are a bunch of them. I partially did this and got the following output
You can see there are two entries posted and both fall in the requested log range of dates, but only one is returned. So at least part of the problem is in how you are constructing your log or how you are saving the entries. Careful examination of the logging output should illuminate the problem.
You also have timezone offset issues as mentioned previously because I don’t see any code to handle them. As you seem to be in UTC locally and the server is in UTC, you may not notice the issue (it’s failing for me now in US CDT). However, that won’t affect this test.
Thank you so much for your help Jeremy - by logging the POST requests and then looking at the exercises actually in the database I realised that I wasn’t posting the exercise for 1990-01-03 - I looked at my code and realised I was testing for already existing exercises by userid and description - I should have been testing for userid and description and duration and date - as soon as I changed that I passed all the tests!!