Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💡 [REQUEST] - Decoupling services #94

Open
devrrior opened this issue Oct 11, 2022 · 0 comments
Open

💡 [REQUEST] - Decoupling services #94

devrrior opened this issue Oct 11, 2022 · 0 comments
Labels
question Further information is requested

Comments

@devrrior
Copy link

Start Date

No response

Implementation PR

No response

Reference Issues

No response

Summary

Create new files where we insert business logic from routes. I mean, pull that blocks of code where it's used mongoose's models out and put it in services files. If you agree with this request, I'd appreciate you can assign me this task.

Basic Example

A common example is when a User is created, that logic which we used, encapsulates in a function from service, then call it in the routes/services. In that way, we are just concerned about calling the function and not how it works.

Example:

Before

const user = new User({
            magic_id: magic_id,
            email: email,
            user_name: user_name,
            encryption_key: encryption_key,
            files: []
        })
        await user.save();

After

const user = UserService.create(magic_id, email, user_name, encryption_key, files);

Drawbacks

Decoupling services are essential for the app, in that way we can become the code more scalable and easier for testing, if the controller handled the whole application's logic and the request-handling logic, it would start to become really hard to test. Furthermore if at some point we want to migrate our database just we would have to create a new file and write the logic with the new database.

Unresolved questions

No response

@devrrior devrrior added the question Further information is requested label Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant