Hi. I am making a node.js app with Express and Mongoose. I am using modular structure (for each new module I am creating a new folder), like this:server orders model.js service.js controller.js users model.js service.js controller.js ... other modules .... index.js <-- this just set ups an Express server and mounts all controllers So a controller accepts HTTP requests, validates them, extracts needed info, calls a service, which does all the business logic and DB quering and then returns the result.My question is: if some business-logic action requires calling multiple services, should they be called by controller or by service?Example: controller has `/users/register` endpoint. It calls Users service, it writes new user to database, and then I need to send an email to new user (MailService) for successful registration and for example, call RecommendationService method so it starts recommending new user as a friend for other users, for example. In that case, the MailService and RecommendationService should be called by controller or by User service?It may sound like a silly question, which does not worth spending time on, but I have multiple cases of that and want to do best-practice and avoid code duplication as much as possible.Thanks in advance.
Submitted April 19, 2020 at 08:55PM by MrOnlineCoder
No comments:
Post a Comment