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

Passing options with UseInterceptor #860

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

driescroons
Copy link

@driescroons driescroons commented Mar 21, 2022

Description

When using routing controllers, I don't want to explicitly set an interceptor to each controller action even though I (might) want to specify the priority, in how they're applied to the controller action.

For example; I have a:

  • Flush interceptor (for mikro-orm)
  • An Interceptor that formats my controller action response (using class-validator and class-transformer)

When I now specify the flush interceptor on global or controller level, it only get's executed after my response has been formatted. I want the flush to happen before any controller action response formatting happens, without having to specify the flush interceptor, on every controller action, below the response formatting interceptor.

This PR suggests a way to pass and specify options (in this case mostly for the priority prop) to the interceptors, and sorts them according to importance before being applied to each controller action.

This PR still requires tests and additional docs, but I want to get some opinions whether this is something that could be merged.

Local development setup used: #861
Project I tested this with (above setup required): https://github.com/driescroons/routing-controllers-interceptor-priority-testing

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

@attilaorosz
Copy link
Member

This is a good proposal and I think we could apply this for the middlewares too. For example you have a specific middleware that you want to run before the global ones.

@driescroons
Copy link
Author

Glad that you bring that up @attilaorosz as I've already been working on that PR as well! A good reason why I think we also need this for middleware is when we want to run authentication before any validation (which is not the case right now), or other middleware, without having to specify it in a specific order on the controller action.

I'll add some tests and docs to this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants