website-backend
website-backend copied to clipboard
Fix: feature to create OOO request
Date: 23 Feb, 2025
Developer Name: @surajmaity1
Issue Ticket Number
- Open #2242
Description
This PR contains a feature for creating OOO requests.
-
Introduced enhanced error messages for request submissions, including specific notifications for OOO requests and user status checks.
-
Added a new type definition for user current status to improve data handling.
-
Updated request payloads by standardizing on a "reason" field and enforcing required fields.
-
Fixed integration and unit tests to verify the updated validations and response formats, including checks for the new "reason" field.
Documentation Updated?
- [x] Yes
- [ ] No
Under Feature Flag
- [x] Yes
- [ ] No
Database Changes
- [x] Yes
- [ ] No
Breaking Changes
- [ ] Yes
- [x] No
Development Tested?
- [x] Yes
- [ ] No
Screenshots
Screenshot 1
https://github.com/user-attachments/assets/131ff8ed-f391-4b01-8b96-439a3bd86428
Screenshot 2
Test Coverage
Screenshot 1
Additional Notes
- The Test PR ( - #2386 ) has to be merged to this PR and then this PR can be merged in develop.
- Documentation PR ( - https://github.com/Real-Dev-Squad/website-api-contracts/pull/223 )
Summary by CodeRabbit
- New Features
- Enhanced out-of-office request handling now provides clearer messages if a request is already pending, the current status isn’t found, or a duplicate request exists.
- Out-of-office submissions now require a clear "reason" for improved clarity.
- Only registered Discord users are permitted to create out-of-office requests.
- Streamlined processing and improved validations deliver a more intuitive and reliable request experience.
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
This pull request enhances out-of-office request handling. It introduces new error and log constants, refines controller logic for OOO requests (with explicit Discord user checks and NextFunction parameters), and updates the Joi validation schema and associated test fixtures to replace "message" with "reason" and remove the "state" field. Additionally, type definitions have been strengthened, and new service functions for user status validation and request creation have been added. Test cases across integration and unit tests have been updated accordingly.
Changes
| File(s) | Change Summary |
|---|---|
constants/requests.ts, constants/logs.ts |
Added new error constants (REQUEST_ALREADY_PENDING, ONLY_DISCORD_USER_CREATE_OOO_REQUEST, USER_STATUS_NOT_FOUND, OOO_STATUS_ALREADY_EXIST) and log constants. |
controllers/oooRequests.ts, controllers/requests.ts |
Updated controller functions with explicit Discord membership verification, added NextFunction parameter, and streamlined the OOO request creation logic. |
middlewares/validators/oooRequests.ts, test/fixtures/oooRequest/oooRequest.ts, test/unit/middlewares/oooRequests.test.ts |
Replaced the message field with reason, removed state, updated the Joi schema, and adjusted test validations and error messages accordingly. |
test/integration/requests.test.ts |
Modified tests to include a dev=true query parameter, updated expected response codes (201 for new, 409 for duplicate, 401 for unauthorized), and altered validation checks. |
types/oooRequest.d.ts |
Refined type definitions by making fields required (e.g., until, reason, requestedBy, userId, createdAt, updatedAt), renaming properties, and adding a comment field. |
services/oooRequest.ts |
Introduced new service functions validateUserStatus and createOOORequest with proper error handling and logging to support the creation flow. |
Sequence Diagram(s)
sequenceDiagram
participant C as Controller (createOooRequestController)
participant S as Service (createOOORequest)
participant V as Service (validateUserStatus)
participant DB as DataStore/Logger
C->>S: Invoke createOOORequest(body, username, userId)
S->>V: Call validateUserStatus(userId, userStatusExists, userStatus)
V-->>S: Return validation result / throw error
S->>DB: Call createRequest & addLog
DB-->>S: Return success confirmation
S-->>C: Return created OOO request response
Poem
I'm hopping through the lines of code,
In fields refreshed with "reason" bestowed.
New constants and tests I joyfully compile,
A streamlined path that makes me smile.
With every bug I nibble away,
I celebrate each change in a bunny ballet!
🐇💻
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
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)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Hello @surajmaity1, since you've created a separate PR for unit and integration tests, could you please update this PR's description and include the link to that test PR as well?
- Please update branch.
- Add screenshots for success and error response for different case.
- Add a screenshot for get request to verify the request is created.
Also create a PR for API doc.
Hi @surajmaity1,
I have a question regarding the state field change. How will this field change affect reading operation in the existing system?
Hi @surajmaity1, I have a question regarding the
statefield change. How will this field change affect reading operation in the existing system?
For the existing system, we previously discussed manually renaming state to status since the number of requests is minimal. While we initially suggested writing a script for this change, it was later decided during the discussion that scripting is unnecessary, and the renaming can be done manually.
tests are missing example- types/userCurrentStatus.d.ts
Hi @iamitprakash , do I need to write test cases for this userStatus.ts file?
I discussed with Prakash. He said that no need. But he told me to get clarification from you. Message reference
tests are missing example- types/userCurrentStatus.d.ts
As discussed with @yesyash , I think we can skip writing test cases for the userStatus.ts file we we have only defined types inside the file and there is not functionality present that has to be test.
Also, when I run yarn test-unit, I don't see the userStatus.ts in the coverage report.