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