Exercise tracker feedback + question

Hi,

I’ve gone through the Exercise tracker challenge and I’d love some feedback, mostly concerning how I’m handling errors. I find that try-catch-blocks make the code very hard to read, so I have a custom error middleware at the end of the pipeline, to catch all errors that I throw in my code (“user already exists”, “user not found”, etc).


I also have a question concerning the last user story. Currently, I’m fetching the user, and then filter the logs array on the server with regular JS. Is there another way? I’ve been busy all day researching how to do that with Mongoose but still clueless.

I don’t think that a query chain would make much sense, because I only have one document (the user) to work on. I think it’s more a question of how to conditionally limit the output. Would that be done with aggregation? $group? $project?

Link to code: https://replit.com/@jsdisco/boilerplate-project-exercisetracker

Link to challenge: https://www.freecodecamp.org/learn/apis-and-microservices/apis-and-microservices-projects/exercise-tracker

Hi @jsdisco !

It looks like a cool project.

I haven’t gotten to the Api section yet so I can’t answer your questions.
But hopefully, my comment will bump up your post and get some fresh eyes on it. :grinning:

Good luck!

Thanks @jwilkin for push I mean unshift (oh god I’ll get my coat…), I don’t expect much feedback though, due to how I split up the code into separate files (closer to a real appliction but a bit annoying to review for the little code involved), and as for the error handling, it’s quite close to how I learned it from a Brad Traversy course so I don’t expect anything being severly wrong with it.

And my question about Mongoose might be going deeper than what’s actually relevant for web developers, it’s certainly beyond the scope of fCC, plus I’m learning that stuff anyway right now, so next week I can probably post the solution to my own question.