-
Notifications
You must be signed in to change notification settings - Fork 273
Add feature to approve or reject OOO request #2384
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
base: develop
Are you sure you want to change the base?
Add feature to approve or reject OOO request #2384
Conversation
b1c2702
to
fb292ef
Compare
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Summary by CodeRabbit
WalkthroughThis pull request introduces new constants for request logging and authorization related to out-of-office (OOO) requests. It adds a new controller function to handle acknowledgment of OOO requests, modifies existing controllers and validators to support this new flow, and integrates updated service functions to validate and process these requests. Type definitions have been updated accordingly, and integration tests have been adjusted to reflect changes in expected outcomes for duplicate request scenarios. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant Ctrl as Acknowledge Controller
participant V as Validator
participant S as OOO Request Service
participant DB as Firestore
C->>Ctrl: Send Acknowledge OOO Request (with requestId, body, userId)
Note over Ctrl: Check query flag & superuser authorization
Ctrl->>V: (Optional) Validate request (acknowledgeOOORequestsValidator)
V-->>Ctrl: Validation passed
Ctrl->>S: Call acknowledgeOOORequest(requestId, body, userId)
S->>DB: Retrieve OOO request document
DB-->>S: Return request data
S->>DB: Validate & update request status
DB-->>S: Acknowledgment result
S-->>Ctrl: Return success response
Ctrl-->>C: Send response with service message
Possibly related issues
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
could you please add a description to this PR? |
and screenshots as well. Even though it is a draft PR, it will help the reviewers. |
1e0668c
to
9d0314b
Compare
9d0314b
to
bdbaebe
Compare
bdbaebe
to
ebb4ee4
Compare
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: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (8)
constants/requests.ts
(2 hunks)controllers/oooRequests.ts
(4 hunks)controllers/requests.ts
(3 hunks)middlewares/validators/oooRequests.ts
(2 hunks)middlewares/validators/requests.ts
(3 hunks)services/oooRequest.ts
(1 hunks)test/integration/requests.test.ts
(1 hunks)types/oooRequest.d.ts
(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
types/oooRequest.d.ts (1)
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2386
File: test/fixtures/oooRequest/oooRequest.ts:59-60
Timestamp: 2025-03-22T14:28:57.808Z
Learning: The `createOooRequests2` object in test/fixtures/oooRequest/oooRequest.ts still uses the old property names `message` and `state` (instead of `reason` and `status`) because it's specifically used in acknowledging OOO request tests. This naming inconsistency will be fixed by surajmaity1 in a dedicated PR for acknowledging OOO requests.
🧬 Code Definitions (5)
middlewares/validators/requests.ts (2)
types/oooRequest.d.ts (2)
AcknowledgeOOORequest
(56-61)OooRequestResponse
(42-42)middlewares/validators/oooRequests.ts (1)
acknowledgeOOORequestsValidator
(42-72)
middlewares/validators/oooRequests.ts (2)
types/oooRequest.d.ts (2)
AcknowledgeOOORequest
(56-61)OooRequestResponse
(42-42)constants/requests.ts (1)
REQUEST_STATE
(1-5)
controllers/oooRequests.ts (3)
constants/requests.ts (2)
REQUEST_STATE
(1-5)UNAUTHORIZED_TO_ACKNOWLEDGE_OOO_REQUEST
(46-46)types/oooRequest.d.ts (2)
AcknowledgeOOORequest
(56-61)OooRequestResponse
(42-42)services/oooRequest.ts (1)
acknowledgeOOORequest
(61-135)
controllers/requests.ts (2)
controllers/oooRequests.ts (1)
acknowledgeOOORequestController
(127-159)types/oooRequest.d.ts (2)
AcknowledgeOOORequest
(56-61)OooRequestResponse
(42-42)
types/oooRequest.d.ts (2)
constants/requests.ts (1)
REQUEST_STATE
(1-5)types/requests.d.ts (2)
RequestQuery
(11-20)RequestParams
(22-24)
🔇 Additional comments (23)
constants/requests.ts (2)
28-29
: Well-structured constants for improved request status logging.These new constants follow the established naming pattern and provide specific log types for already approved or rejected requests, enhancing error handling clarity.
46-46
: Clear authorization message for OOO request acknowledgment.This constant effectively communicates the permission requirements, clearly indicating that only super users can acknowledge OOO requests.
test/integration/requests.test.ts (1)
107-109
:❓ Verification inconclusive
Verify behavioral change in duplicate request handling.
The test now expects a successful response (201) with a "REQUEST_CREATED_SUCCESSFULLY" message when creating a duplicate request, rather than the previous error response (400) with "REQUEST_ALREADY_PENDING". This represents a significant change in how duplicate requests are handled.
🏁 Script executed:
#!/bin/bash # Verify if this behavior change is intentional by checking the controller logic # and related PRs or issue discussions # Check request creation controller logic rg -A 10 "REQUEST_ALREADY_PENDING" --type tsLength of output: 6549
Action Required: Confirm Consistency of Duplicate Request Handling Behavior
The integration test in
test/integration/requests.test.ts
now expects a 201 response with a"REQUEST_CREATED_SUCCESSFULLY"
message for duplicate requests. However, our grep results show that other parts of the codebase—such as intest/integration/onboardingExtension.test.ts
,controllers/onboardingExtension.ts
, andcontrollers/oooRequests.ts
—still rely on the error response with"REQUEST_ALREADY_PENDING"
when handling duplicates. Please verify that this behavioral change is intentional and consistent with the overall design. If the change is deliberate, ensure that the updated behavior is clearly documented and that similar endpoints are aligned accordingly.services/oooRequest.ts (3)
24-59
: Well-structured validation function with proper error handling.The validation function follows good practices by:
- Checking request type validity
- Verifying request status isn't already approved or rejected
- Including appropriate error logging
- Using consistent error handling patterns
87-101
: Elegant pattern for conditional message and log type selection.Good use of array destructuring and a ternary operator to concisely determine the appropriate log type and return message based on the request status.
105-122
: Comprehensive handling of approved requests.The function properly creates and adds future status data for approved OOO requests, ensuring the user's status will be updated at the appropriate time.
middlewares/validators/oooRequests.ts (2)
4-4
: Updated import to include new type.The import statement correctly adds the
AcknowledgeOOORequest
type needed for the new validator function.
42-72
: Well-structured validator with appropriate validation rules.The validator:
- Uses Joi schema validation consistently with other validators
- Properly validates that status must be APPROVED or REJECTED
- Makes comment optional but ensures it's not empty if provided
- Includes appropriate error handling with clear error messages
middlewares/validators/requests.ts (3)
4-5
: Approve import additions for OOO request acknowledgment.The import changes correctly include the new
AcknowledgeOOORequest
type andacknowledgeOOORequestsValidator
function needed for the OOO request acknowledgment feature.
133-135
: Function parameter type correctly updated to support new OOO acknowledgment flow.The parameter type expansion to include
AcknowledgeOOORequest
properly enables the validator to handle both update requests and OOO acknowledgment requests.
140-143
: Appropriate conditional handling for undefined type.This new condition correctly handles the case where the request type is undefined, routing it to the OOO acknowledgment validator. This aligns with the design of having acknowledgment requests without a type field.
controllers/oooRequests.ts (5)
1-1
: Approve import updates for OOO acknowledgment feature.The necessary imports have been added to support the new OOO acknowledgment functionality, including the required types, constants, and service functions.
Also applies to: 13-13, 20-20, 22-22
36-36
: Changed property reference from 'state' to 'status'.The property reference has been updated from
state
tostatus
, which aligns with the changes in theOooStatusRequest
type. This ensures consistency in how the request state is referenced.
127-137
: Feature flag implementation for controlled rollout.The controller properly implements a feature flag check to ensure the feature is only available in development mode. This allows for controlled testing before full release.
138-146
: Security check for superuser role.Good implementation of permission checking to ensure only superusers can acknowledge OOO requests, as required by the feature specification.
155-158
: Error handling follows best practices.The error handling pattern follows best practices by logging the error and passing it to the next middleware for centralized error handling.
controllers/requests.ts (3)
8-9
: Approve import updates for OOO acknowledgment functionality.The necessary imports have been added to support the OOO acknowledgment feature, including the controller function and required types.
Also applies to: 19-19
123-123
: Function signature updated to support middleware chain.Adding the
next
parameter to the function signature properly enables it to participate in Express middleware chains, which is necessary for error handling in the OOO acknowledgment flow.
126-129
: Route undefined type requests to OOO acknowledgment controller.This new conditional logic appropriately routes requests with undefined type to the OOO acknowledgment controller, aligning with the design where acknowledgment requests don't specify a type.
types/oooRequest.d.ts (4)
12-20
: Type definitions updated to support OOO request flow.The updates to the
OooStatusRequest
type properly reflect the new requirements for OOO requests, including required fields and proper type constraints. The change fromstate
tostatus
aligns with the naming convention being used elsewhere in the codebase.
47-49
: Feature flag query parameter type definition.The
AcknowledgeOOORequestQuery
type correctly extendsRequestQuery
with the optionaldev
parameter used for feature flagging.
51-54
: OOO acknowledgment request body type properly defined.The body type for acknowledging OOO requests is well-structured with the required
status
field and optionalcomment
field, matching the validation schema in the middleware.
56-61
: Complete type definition for the OOO acknowledgment request.The
AcknowledgeOOORequest
type properly extends the baseRequest
type with all necessary properties for handling OOO acknowledgments, ensuring type safety throughout the request processing flow.
ebb4ee4
to
0e60e6d
Compare
8522627
to
5540a2e
Compare
08ff3d1
to
04d1bfe
Compare
04d1bfe
to
6b497b1
Compare
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.
Hi @surajmaity1,
One of the tests is failing. Could you please take a look when you get a chance?
Thanks!
Hi @AnujChhikara , The test case for the creation of the OOO request has failed. However, I have already addressed this test case in the PR - Thank you. |
After the OOO request is approved, the user's |
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.
LGTM
My comments have been resolved. Therefore approved it.
5296265
8fa2496
to
7f2e9dc
Compare
5aa7e39
7f2e9dc
to
5aa7e39
Compare
controllers/oooRequests.ts
Outdated
|
||
if(!dev) return res.boom.notImplemented("Feature not implemented"); | ||
|
||
const isSuperuser = req.userData.roles?.super_user; |
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.
please add optional chaining to req.userData?.roles to prevent potential null/undefined errors if userData isn't properly initialized.
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.
Hi Amit sir,
it's fixed.
controllers/oooRequests.ts
Outdated
|
||
const requestBody = req.body; | ||
const superUserId = req.userData.id; | ||
const requestId = req.params.id; |
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.
please add validation for requestId
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.
Hi Amit sir,
it's fixed.
* @param {OooRequestResponse} res - The response object. | ||
* @returns {Promise<OooRequestResponse>} Resolves with success or failure. | ||
*/ | ||
export const acknowledgeOooRequest = async ( |
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.
NIT: please move the entire function body inside the try-catch block to capture all potential errors, including those that might occur during parameter extraction
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.
Hi Amit sir,
it's fixed.
@surajmaity1 please use below
|
680fe42
5aa7e39
to
680fe42
Compare
Hi Amit sir, |
Date: Date: 23 Feb, 2025
Developer Name: Suraj Maity ( @surajmaity1 )
Issue Ticket Number
Description
This PR contains feature related to approval and rejection of OOO requests by super-users.
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
final.acknowledgement.ooo.mp4
Screenshot 2
Test Coverage
Additional Notes