-
Notifications
You must be signed in to change notification settings - Fork 0
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: create AccountServices module and refactor access controller #194
Conversation
Moved code for getting account into new service layer module in models/services/account.ts and added unit tests for getAccount
app.ts had a build error due to the User type mismatching between the passport and passport-local-mongoose packages. To fix this, I modified our custom Express.user type to extend UserType. This commit also cleans up User and the previous workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @davidzlu! Particularly on resolving that build error 😁 I have some feedback and suggested some changes. Please take a look when you get the chance.
Integrate code review comments for getAccount refactor.
Moved code for updating journal into service layer function and added unit tests for updateJournal
Move business logic for updateAccount into account services. Split into updateProfile, updatePassword, and updateConfig. Add unit tests.
Refactor deleteItem into deleteConfig and deleteAccount service functions, and write unit tests.
Refactor controller function to move account creation into createAccount service function. Move validateJournal call into earlier in middleware chain. Add unit test for createAccount.
Refactor verifyEmail into verifyEmail service function, and add unit tests for verifyEmail service function.
Refactor resetPassword in access controller into resetPassword service function and add unit tests.
Have controller check if error thrown by service function and pass to error handler instead of creating 500 ExpressError.
Refactor forgotPassword into forgotPassword service function and rewrite using async/await instead of callback style. Add unit tests.
Refactor login controller handler into several functions and add unit tests for ensureUserJournal.
Refactor tokenLogin in access controller.
The arguments for AccountServices.resetPassword were passed in the wrong order for the resetPassword controller handler. This commit corrects the order of the arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really fine work @davidzlu! 🚀 I have tried my best to carefully review everything over the last 3 days and left some suggestions. Please take a look and let me know if you have any questions or would like to discuss anything. The access controller is looking pristine with this service layer! ✨
Co-authored-by: Ryan James Meneses <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @davidzlu. Is it strange to say I'm proud of you? Because I'm proud of you! 😁
Note: This PR was originally for refactoring just the get operations in the access controller before it was expanded to refactoring the entire access controller. This is why the branch name is still
139-get-access-operations
.This PR:
There was a tsc error where the user type in the passport and and passport-local-mongoose modules didn't match. This was caused by the way Express.User was getting defined in our custom type declaration file. Express.User now extends the CDJ UserType in models to resolve the build error.