Exercise Tracker To, From and Limit Criteria not passing

Hi,

Been trying to complete this for a few days at this point and I’ve been completely defeated.

I cannot figure out why I am not passing the last criteria. Every manual test I could figure out comparing my results to the FCC ones are bang on as far as I can tell and therefore I have spent hours trying to figure out why it doesn’t without any idea whatsoever on what is wrong it.

I have been trying to diagnose using Postman to no Avail and have reached the limit of my determination on this so any help is greatly appreciated.

My code is at the following: https://repl.it/@LaurentLabine/boilerplate-project-exercisetracker#server.js

Cheers

Challenge: Exercise Tracker

Link to the challenge:

Welcome to the forums @laurentlabine.

I’ve finally had a chance to take a look at your project. There are a few things I found that may be causing problems.

var limit = req.query.limit === undefined? 10 : req.query.limit

First, you set limit to 10 if req.query.limit is undefined. The tests are not checking this, but the server is supposed to return all records if there is no limit.

I believe the main problem is this conditional:

if (userId === undefined) {
...
} else if(req.query.from === undefined && req.query.to === undefined ){
...
} else {//All parameters there.  Search for logs
...
}

I added some console.log(...) calls before each response to track the execution and responses, and realized that this code never uses the limit unless from, to, and limit are all provided since all the limit logic is in the else of the conditional. The limit needs to be applied even if there are no from/to dates. The tests for this create two entries and then test for all of them and then tests the limit by asking for one of them; when I logged everything, two entries were returned for both tests.

Additionally, when you want to send a response, it is always best to use return res.json({...}), etc., to stop execution in the route. Otherwise, you may send multiple responses. You may want to add console.log(...) calls before each response in your route during these tests as I saw some other oddities that may affect the tests as well.

Good luck.

Thank you so much for your help! You were bang on! I managed to fix it following your insights!

One last part I was wondering… I initially found a way to build a query to fetch considering the dates directly into my mongo db query but then realize i had to use a string format to store the dates in the format wanted for the challenge (or convert it every time i sent the results after fetching them) so I ended up creating another object i populated basically (doc results object being immutable and all).

It does work but I do feel like it is the worst way of doing things without really knowing how else i could have managed… Would you have done it differently?

Thank you again!

I agree completely, I just did the exact opposite from you and stored date objects and passed date strings from the start and the tests all passed. My guess is that the test server and MongoDB are both using UTC and there are no time zone offsets to worry about. The only problem I had was when I recently added functional tests for the routes, I had to add some time mangling with the time zone offset to make sure the tests passed locally because the tests were running in Central Standard Time and the MongoDB server is in UTC. You are also correct about it making the dates much easier to handle when fetching records from MongoDB.

I can think of no good reason to store or pass a string date and not a Date object in a new, real project. This way, all the dates are in UTC and the client can sort out how to display that in the local timezone.

That makes sense!

Thanks!