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

refactor: use combined route validators and handlers #2819

Closed

Conversation

tehtea
Copy link
Contributor

@tehtea tehtea commented Sep 19, 2021

Problem

Prevent developers from forgetting the use of validators when using a controller handler.

Closes #1642

Solution

As suggested in the issue, put the original handler with a validation middleware in an array, and expose the final array for usage rather than the original handler

Breaking Changes

  • Yes - this PR contains breaking changes
    • Details ...
  • No - this PR is backwards compatible

Improvements:

  • Details ...

Tests

Ran a regression test using npm run test-backend, and ran happy-path testing locally with the changed routes

Sorry, something went wrong.

@tehtea
Copy link
Contributor Author

tehtea commented Sep 19, 2021

Only added the change for the contact verification OTP for now, to verify the approach and also to check if there are any particular routes to not put this change on.

Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @tehtea for the contribution, the approach is correct! in addition, you can delete the validation middleware for this route from user.routes.ts so that the middleware does not run twice.

* Celebrate validation for the contact OTP verification endpoint.
*/
export const validateContactOtpVerificationParams = celebrate({
body: Joi.object({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we normally use the Segments enum exposed by celebrate to avoid accidentally misnaming the keys. see user.routes.ts for reference

@tehtea tehtea marked this pull request as ready for review October 4, 2021 16:00
@tehtea
Copy link
Contributor Author

tehtea commented Oct 4, 2021

Done! Nah, thank you all for open-sourcing this project, I learned a lot of good practices from here! Applied the changes to other routes I could find, feel free to take a look.

@liangyuanruo liangyuanruo requested a review from karrui October 12, 2021 10:24
Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for taking such a long time to get back to this PR. Everything looks great, thank you for picking up this issue!

Will run the tests and merge if it passes

@karrui karrui changed the title Combine Validators and Handlers refactor: use combined route validators and handlers Oct 12, 2021
@karrui
Copy link
Contributor

karrui commented Oct 12, 2021

Some checks seem to not be starting, @tehtea do you mind pushing an empty commit to see if that would retrigger the CI/CD?

@tehtea
Copy link
Contributor Author

tehtea commented Oct 12, 2021 via email

@karrui karrui requested a review from tshuli October 19, 2021 02:32
@karrui
Copy link
Contributor

karrui commented Oct 26, 2021

@tehtea sorry for the slowness, still figuring out why only some CI/CD are running... :(

@tehtea
Copy link
Contributor Author

tehtea commented Nov 4, 2021

@karrui Hey no worries! Just a minor refactor after all, not sure how to trigger the test actions on my end too...

@karrui
Copy link
Contributor

karrui commented Dec 7, 2021

@tehtea can you try merging develop into this PR and see if the CI/CD gets triggered? If that still does not work, as a last resort, I will pull your branch and reopen this PR

@tehtea tehtea force-pushed the refactor/combine-validators-and-handlers branch from d7cdbf5 to 43af205 Compare December 9, 2021 14:10
@tehtea
Copy link
Contributor Author

tehtea commented Dec 9, 2021

@karrui Okay, just rebased the commits and force-pushed, let's see how it goes

@karrui
Copy link
Contributor

karrui commented Dec 13, 2021

Sorry for the wait, we should be able to trigger our CI/CD once #3175 is merged in.

@karrui
Copy link
Contributor

karrui commented Dec 13, 2021

@tehtea should work now if you rebase and push again. Thank you so much for being patient and we're so sorry that it took so long to get this handled :(

@tehtea
Copy link
Contributor Author

tehtea commented Dec 15, 2021

@karrui No worries, these things happen :) pushed some minor changes, here's hoping it works.

@tshuli
Copy link
Contributor

tshuli commented Feb 14, 2022

merged in #3428

@tshuli tshuli closed this Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combine validators with handler functions and export them atomically
4 participants