Tell us what’s happening:
Can’t pass test 8 and tests 10-16 . Tried checking the types but all of them matches the test requirements (element of log is an object, description is a string, duration is a number, date is a string). The exercise route and count property for log route as well as querying seems to be working fine (responses are identical to the example from my point of view) as well but also doesn’t pass the tests. Don’t know what’s wrong. Any help would be appreciated. Thanks very much.
After some testing, it seems that the problem is the exercise post route and exercises are, in fact, not being added. I’m guessing that’s because FCC tests do not input anything to the ‘:_id’ field. Am I misunderstanding how the exercise post route works?? I thought all fields are required except date.
Got all other tests passing except the last one by getting _id from req.params instead of req.body. Yet, I still don’t get how the ‘post request params’ thing work (how can the FCC test not pass in _id through the form but instead through route param for a post request???), can anyone explain to me please. Thank you.
You see that it’s :_id (notice semicolon). For express it means match the requested url and stuff that goes in the place of :_id assign to a params._id object.
So for the url /api/users/sponge-bob/exercises it’ll be params._id = "sponge-bob".
Thanks for replying. Right, I get the sponge-bob thing. But if I directly type the _id into the url, isn’t it a get request instead of a post request? From my understanding, a post request will ask the client to fill in a form which the information can then be accessed by using req.body. Yet, I found that the FCC test didn’t input any _id to the form when calling the post request and hence ‘req.body[":_id"]’ (’:_id’ is the name of the _id field of the form) gives undefined. So the thing that confuses me is how FCC can pass _id without filling in the corresponding field of the form for a post request. Thanks again.
Hmmmm. But from the perspective of a normal user, don’t we add exercises by filling in the form? So when I press the submit button with the :_id field filled in, a post request with route shown in the picture (second line) is made (am I right?). Now my question would be how does the _id get added to the route when it is treated as form data and hence should be accessed via req.body? Sorry for being ignorant. Thanks.