-
Notifications
You must be signed in to change notification settings - Fork 34
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
392 refactoring validations in team and invite routes with express validator #443
392 refactoring validations in team and invite routes with express validator #443
Conversation
WalkthroughThe pull request introduces several configuration and utility improvements to the backend project. A new Prettier configuration file and ESLint configuration have been added to standardize code formatting and linting. The Changes
Sequence DiagramsequenceDiagram
participant Client
participant TeamRoutes
participant Middleware
participant TeamController
participant Database
Client->>TeamRoutes: Send team management request
TeamRoutes->>Middleware: Apply authentication
Middleware->>TeamRoutes: Validate access
TeamRoutes->>Middleware: Apply request validation
Middleware->>TeamController: Execute handler
TeamController->>Database: Perform database operation
Database->>TeamController: Return result
TeamController->>Client: Send response
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🔇 Additional comments (1)backend/src/test/unit/controllers/team.test.js (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
backend/package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (7)
backend/.prettierrc
(1 hunks)backend/eslint.config.mjs
(1 hunks)backend/package.json
(1 hunks)backend/postman/Team.postman_collection.json
(1 hunks)backend/src/controllers/team.controller.js
(3 hunks)backend/src/routes/team.routes.js
(1 hunks)backend/src/utils/team.helper.js
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- backend/.prettierrc
🧰 Additional context used
🪛 Gitleaks (8.21.2)
backend/postman/Team.postman_collection.json
17-17: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
78-78: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
118-118: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
158-158: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
190-190: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
219-219: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
(jwt)
🔇 Additional comments (34)
backend/eslint.config.mjs (2)
1-2
: All good importing globals and pluginJs
The import statements for globals
and @eslint/js
are correctly placed, which helps us keep our linter configuration concise and organized.
5-10
: Solid ESLint configuration setup
Specifying commonjs
and using globals.node
plus pluginJs.configs.recommended
provides a coherent baseline for linting Node.js projects. This approach keeps your environment rules consistent and robust.
backend/package.json (1)
35-39
: Sensibly adding linting and global dependencies
Adding these development dependencies (@eslint/js
, eslint
, and globals
) fortifies your code quality measures, ensuring your codebase aligns with recognized standards.
backend/src/utils/team.helper.js (9)
1-2
: Imports alignment
Your newly added imports look consistent with the code usage for URL and validation.
6-8
: Ensure empty string usage
Permitting an empty string as a valid server URL might lead to accidental misconfigurations if a user does not provide an actual URL.
Also applies to: 14-14
28-31
: Return objects
Returning consistent object structures is beneficial for downstream usage; your approach is good.
37-49
: Validation array
This custom validator is well crafted. The use of optional fields and custom checks is well done.
51-62
: Validate organization name
The mix of .notEmpty(), .isLength(), and regex ensures robust input validation. This is a strong approach.
64-79
: Invitation validation
Your checks for both the invited email and role are well structured and thorough.
81-96
: Change role validation
Ensuring that the role is one of {admin, member} is a great practice.
98-103
: Param validation
Requiring a numeric 'memberId' helps maintain data integrity.
106-112
: Export structure
All relevant validation helpers are exported correctly, making them straightforward to import in other modules.
backend/src/routes/team.routes.js (9)
1-2
: Consistent import statements
Using single quotes consistently aligns with your new Prettier configuration.
17-22
: New validation imports
Great job pulling in all relevant validators from team.helper.
28-31
: Global JWT usage
Applying router.use(authenticateJWT)
globally ensures consistent authentication.
33-39
: Set organization route
Inserting validateOrganizationName
and handleValidationErrors
ensures robust input checks before handler execution.
40-40
: Invite route
The new validationInvite
usage is correct.
41-47
: Update route
Applying validateOrganizationName
again for the team name is consistent with your set-organisation approach.
48-54
: Change-role route
Using the validationChangeRole
array with handleValidationErrors
is clear and maintainable.
55-61
: Set server-url route
Attaching validateSetServerUrl
is aligned with your helper logic.
63-70
: Remove & get-all-invites
validateIdParam
for the remove route is a wise addition, ensuring a valid numeric memberId.
backend/src/controllers/team.controller.js (13)
1-4
: Refreshed imports
Imports for settings and services remain well structured, enhancing clarity.
20-25
: Success message
Replacing references with "Organization created successfully" is consistent with the rest of the naming.
28-28
: Consistent error handling
Logging the error and sending an internal server error response is good practice.
39-39
: Use of internal server error
Maintains consistency with your error strategy.
47-51
: Defaulting null to empty
Returning an empty string for null serverUrl can be beneficial for client behaviour.
59-60
: Optional chaining
Great usage of optional chaining (?.
) for safe property access.
63-71
: Mapping user details
Providing a formatted date for each user is a nice usability feature.
74-74
: Error response
Centralized error handling ensures consistent client messaging.
80-87
: UpdateTeam
Your approach to update the team name is straightforward, returning a clear success message.
94-96
: Set server URL
Aligns perfectly with the new validation in team.helper.
99-99
: Remove member
Deleting a user from the team with the service method and returning a success message is easy to understand.
Also applies to: 106-108, 111-111
117-119
: Change role
Properly aligning the user’s role with expected values is a big step in controlling permissions.
Also applies to: 122-122
124-134
: Module exports
Exporting all controller functions ensures easy integration with your routes.
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.
The validations look good.
Describe your changes
Briefly describe the changes you made and their purpose.
Issue number
Mention the issue number(s) this PR addresses (e.g., #123).
Please ensure all items are checked off before requesting a review: