Skip to content

Conversation

@RishiChaubey31
Copy link
Contributor

@RishiChaubey31 RishiChaubey31 commented Aug 23, 2025

Date: 25-08-2025

Developer Name: Rishi Chaubey


Issue Ticket Number

Description

  1. When a user creates OOO request it has to be acknowledged by a SUPERUSER
  2. Superuser can acknowledge or reject the OOO request.
  3. The system tracks acknowledgements and updates the OOO status accordingly.
  4. If all required acknowledgements are received, the OOO status is marked as acknowledged.

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
acknow-test.mp4
Screenshot 2025-09-01 035209 Screenshot 2025-09-01 035340

Test Coverage

Screenshot 1 image Screenshot 2025-09-03 011250 Screenshot 2025-09-03 011039

Additional Notes

Description by Korbit AI

What change is being made?

Implement an Out-of-Office (OOO) acknowledgment functionality to update the status of OOO requests, including related middleware, validation, and service enhancements.

Why are these changes being made?

These changes allow superusers to acknowledge OOO requests by approving or rejecting them, thereby improving request management efficiency. This implementation ensures a clear and consistent process for handling OOO requests with proper validation and error handling.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

@coderabbitai
Copy link

coderabbitai bot commented Aug 23, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • New Features
    • Superusers can now acknowledge (approve/reject) OOO requests through the update flow with clear success messages.
    • Dev-flag and role checks apply conditionally for OOO acknowledgments.
    • Request ID is required for acknowledgments, with clearer error responses on failures.
    • Prevents re-acknowledging requests that are already approved or rejected.
    • Requests list now supports filtering by status (approved/pending/rejected).
    • Stricter validation for OOO acknowledgment payloads to ensure accurate inputs.

Walkthrough

Adds OOO request acknowledgement flow: new constants and types; controller to acknowledge OOO requests; validators and conditional middleware; routing update to insert conditional checks; services extended to validate/acknowledge and refactor OOO creation signature; model helper to fetch request by ID; controllers wired to new flow.

Changes

Cohort / File(s) Summary
Constants
constants/requests.ts
Added REQUEST_ALREADY_APPROVED/REQUEST_ALREADY_REJECTED to REQUEST_LOG_TYPE; added ERROR_WHILE_ACKNOWLEDGING_REQUEST and REQUEST_ID_REQUIRED exports.
Types
types/oooRequest.d.ts
Added AcknowledgeOooRequestQuery, AcknowledgeOooRequestBody, AcknowledgeOooRequest types.
Services (OOO)
services/oooRequest.ts
Refactored createOooRequest signature to (body, requestedBy); added validateOooAcknowledgeRequest and acknowledgeOooRequest with future status side effects on approval.
Controllers (OOO)
controllers/oooRequests.ts
Updated create call to new signature; added acknowledgeOooRequest controller with dev flag, superuser, and requestId checks; error handling via next.
Controllers (Requests)
controllers/requests.ts
updateRequestBeforeAcknowledgedController now accepts next; routes OOO type to acknowledgeOooRequest with typed req/res.
Middleware (Conditional)
middlewares/conditionalOooChecks.ts
New conditional middleware: for OOO type, applies dev flag and SUPERUSER role checks; otherwise passes through.
Middleware (Validators - OOO)
middlewares/validators/oooRequests.ts
Added Joi schema and acknowledgeOooRequest validator for OOO acknowledgements; preserves existing create validator.
Middleware (Validators - Requests)
middlewares/validators/requests.ts
Extended getRequests schema with status filter; updateRequestValidator now handles OOO by invoking acknowledgeOooRequest validator; updated types.
Models (Requests)
models/requests.ts
Added getRequestById with NotFound handling and error logging.
Routes
routes/requests.ts
Inserted conditionalOooChecks into PATCH /:id chain: authenticate → conditionalOooChecks → updateRequestValidator → updateRequestBeforeAcknowledgedController.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant R as Router
  participant Auth as authenticate
  participant Cond as conditionalOooChecks
  participant Val as updateRequestValidator
  participant Ctrl as updateRequestBeforeAcknowledgedController
  participant OCtrl as acknowledgeOooRequest (controller)
  participant S as oooRequestService
  participant M as Models (getRequestById/updateRequest)
  participant FS as Future Status Services

  C->>R: PATCH /requests/:id
  R->>Auth: authenticate
  Auth-->>R: ok
  R->>Cond: conditionalOooChecks
  alt type === OOO
    Cond->>Cond: devFlagMiddleware
    Cond->>Cond: authorizeRoles([SUPERUSER])
  else other types
    Cond-->>R: next()
  end
  R->>Val: updateRequestValidator
  alt type === OOO
    Val-->>Ctrl: next()
    Ctrl->>OCtrl: delegate (req,res,next)
    OCtrl->>S: acknowledgeOooRequest(id, body, superUserId)
    S->>M: getRequestById(id)
    S->>S: validateOooAcknowledgeRequest()
    S->>M: updateRequest(...)
    alt status APPROVED
      S->>FS: addFutureStatus(...)
      S->>FS: createUserFutureStatus(...)
    end
    S-->>OCtrl: {message}
    OCtrl-->>C: 200 {message}
  else other types
    Ctrl->>Ctrl: existing flows
    Ctrl-->>C: response
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

backend

Suggested reviewers

  • AnujChhikara
  • MayankBansal12
  • Achintya-Chatterjee
  • pankajjs

Poem

A whisk of ears, I patch with grace,
OOO requests now know their place.
Approve or nix, with logs aligned,
Future states neatly intertwined.
I hop through middleware’s gate—
Superuser checked, we validate.
Thump-thump, shipped! 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/ooo-req-acknowledgement

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added the backend label Aug 23, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Functionality Missing Required Parameter in Service Call ▹ view
Design Inconsistent Module Import Pattern ▹ view ✅ Fix detected
Files scanned
File Path Reviewed
middlewares/conditionalOooChecks.ts
types/oooRequest.d.ts
routes/requests.ts
middlewares/validators/oooRequests.ts
constants/requests.ts
models/requests.ts
controllers/requests.ts
middlewares/validators/requests.ts
controllers/oooRequests.ts
services/oooRequest.ts

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 21

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
routes/requests.ts (1)

1-6: Fix ESLint “import/first”: move router initialization below imports

const router = express.Router(); (Line 2) precedes an import statement on Line 6, triggering import/first. Move router initialization after all imports.

-import express from "express";
-const router = express.Router();
+import express from "express";
 const authorizeRoles = require("../middlewares/authorizeRoles");
 const { SUPERUSER } = require("../constants/roles");
 import authenticate from "../middlewares/authenticate";
 import { conditionalOooChecks } from "../middlewares/conditionalOooChecks";
+const router = express.Router();
controllers/requests.ts (2)

1-6: Reuse constant for invalid type to keep responses consistent

Use INVALID_REQUEST_TYPE from constants instead of string literals.

 import {
   ERROR_WHILE_FETCHING_REQUEST,
   REQUEST_FETCHED_SUCCESSFULLY,
-  REQUEST_TYPE,
+  REQUEST_TYPE,
+  INVALID_REQUEST_TYPE,
 } from "../constants/requests";

124-136: Wire OOO acknowledge path looks correct; unify default error message

The OOO branch correctly forwards to acknowledgeOooRequest with next. For the default branch, prefer the shared constant.

   default:
-      return res.boom.badRequest("Invalid request");
+      return res.boom.badRequest(INVALID_REQUEST_TYPE);

Optional: return await acknowledgeOooRequest(...) to make flow explicit (not required since you break immediately).

types/oooRequest.d.ts (1)

17-18: createdAt/updatedAt type mismatch with actual model values

The models set createdAt/updatedAt via Date.now() (number). Declaring them as Timestamp here is inconsistent and can mislead callers.

-  createdAt: Timestamp;
-  updatedAt: Timestamp;
+  createdAt: number;
+  updatedAt: number;

Also change OooRequestUpdateBody.updatedAt from admin.firestore.Timestamp to number for consistency.

controllers/oooRequests.ts (1)

48-53: Remove unused variable

username is no longer used after changing the service signature.

-  const { id: userId, username } = req.userData;
+  const { id: userId } = req.userData;
middlewares/validators/requests.ts (1)

132-151: Delegate OOO updates to the acknowledge validator, but ensure type narrowing

Good call to route OOO updates through the new acknowledge validator. For clarity to TS, cast req to AcknowledgeOooRequest at the call site.

-      case REQUEST_TYPE.OOO:
-          await acknowledgeOooRequest(req, res as OooRequestResponse, next);
+      case REQUEST_TYPE.OOO:
+          await acknowledgeOooRequest(req as AcknowledgeOooRequest, res as OooRequestResponse, next);
           break;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3b70472 and 402cc8b.

📒 Files selected for processing (10)
  • constants/requests.ts (2 hunks)
  • controllers/oooRequests.ts (4 hunks)
  • controllers/requests.ts (3 hunks)
  • middlewares/conditionalOooChecks.ts (1 hunks)
  • middlewares/validators/oooRequests.ts (2 hunks)
  • middlewares/validators/requests.ts (4 hunks)
  • models/requests.ts (2 hunks)
  • routes/requests.ts (2 hunks)
  • services/oooRequest.ts (4 hunks)
  • types/oooRequest.d.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2386
File: test/unit/services/oooRequest.test.ts:9-9
Timestamp: 2025-03-16T05:28:26.722Z
Learning: PRs #2383 and #2386 are related. PR #2383 implements the OOO request feature with the services/oooRequest.ts file, while PR #2386 adds tests for this feature. This creates a dependency where PR #2386 requires PR #2383 to be merged first.
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2386
File: test/fixtures/oooRequest/oooRequest.ts:59-60
Timestamp: 2025-03-16T05:23:33.460Z
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.
📚 Learning: 2025-03-16T05:23:33.460Z
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2386
File: test/fixtures/oooRequest/oooRequest.ts:59-60
Timestamp: 2025-03-16T05:23:33.460Z
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.

Applied to files:

  • types/oooRequest.d.ts
  • controllers/requests.ts
  • controllers/oooRequests.ts
  • middlewares/validators/oooRequests.ts
  • constants/requests.ts
  • services/oooRequest.ts
  • middlewares/validators/requests.ts
📚 Learning: 2025-03-09T06:30:20.120Z
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2383
File: types/userCurrentStatus.d.ts:3-9
Timestamp: 2025-03-09T06:30:20.120Z
Learning: The naming inconsistency between `message` in types/userCurrentStatus.d.ts and `reason` in OOO request models will be fixed by surajmaity1 in a future PR when modifying the user status route.

Applied to files:

  • types/oooRequest.d.ts
  • controllers/requests.ts
  • controllers/oooRequests.ts
  • services/oooRequest.ts
📚 Learning: 2025-06-26T20:08:47.146Z
Learnt from: Suvidh-kaushik
PR: Real-Dev-Squad/website-backend#2450
File: services/impersonationRequests.ts:11-11
Timestamp: 2025-06-26T20:08:47.146Z
Learning: In services/impersonationRequests.ts, the functions `updateImpersonationRequest` and `getImpersonationRequestById` are being imported from models/impersonationRequests but appear missing because they exist in previous PRs that need to be merged before this PR. This is expected behavior for dependent PRs and the build failures are temporary.

Applied to files:

  • models/requests.ts
📚 Learning: 2025-03-16T05:28:26.722Z
Learnt from: surajmaity1
PR: Real-Dev-Squad/website-backend#2386
File: test/unit/services/oooRequest.test.ts:9-9
Timestamp: 2025-03-16T05:28:26.722Z
Learning: PRs #2383 and #2386 are related. PR #2383 implements the OOO request feature with the services/oooRequest.ts file, while PR #2386 adds tests for this feature. This creates a dependency where PR #2386 requires PR #2383 to be merged first.

Applied to files:

  • controllers/requests.ts
  • controllers/oooRequests.ts
  • services/oooRequest.ts
  • middlewares/validators/requests.ts
📚 Learning: 2025-06-22T16:48:33.847Z
Learnt from: Suvidh-kaushik
PR: Real-Dev-Squad/website-backend#2446
File: services/impersonationRequests.ts:129-158
Timestamp: 2025-06-22T16:48:33.847Z
Learning: In services/impersonationRequests.ts, the updateImpersonationRequest model function can perform two types of updates: updating the status and updating the body. When updating the status, a type assertion `as UpdateImpersonationStatusModelResponse` is required to access the status property, as the function returns different types depending on the update operation being performed.

Applied to files:

  • controllers/oooRequests.ts
  • services/oooRequest.ts
🧬 Code graph analysis (9)
types/oooRequest.d.ts (2)
types/requests.d.ts (2)
  • RequestQuery (11-20)
  • RequestParams (22-24)
constants/requests.ts (2)
  • REQUEST_TYPE (13-19)
  • REQUEST_STATE (1-5)
middlewares/conditionalOooChecks.ts (2)
constants/requests.ts (1)
  • REQUEST_TYPE (13-19)
middlewares/devFlag.ts (1)
  • devFlagMiddleware (4-15)
routes/requests.ts (3)
middlewares/conditionalOooChecks.ts (1)
  • conditionalOooChecks (16-32)
middlewares/validators/requests.ts (1)
  • updateRequestValidator (137-155)
controllers/requests.ts (1)
  • updateRequestBeforeAcknowledgedController (124-136)
models/requests.ts (1)
constants/requests.ts (1)
  • ERROR_WHILE_FETCHING_REQUEST (41-41)
controllers/requests.ts (4)
constants/requests.ts (1)
  • REQUEST_TYPE (13-19)
controllers/oooRequests.ts (1)
  • acknowledgeOooRequest (163-197)
middlewares/validators/oooRequests.ts (1)
  • acknowledgeOooRequest (71-84)
types/oooRequest.d.ts (2)
  • AcknowledgeOooRequest (56-61)
  • OooRequestResponse (37-37)
controllers/oooRequests.ts (4)
services/oooRequest.ts (2)
  • createOooRequest (67-101)
  • acknowledgeOooRequest (142-197)
middlewares/validators/oooRequests.ts (1)
  • acknowledgeOooRequest (71-84)
types/oooRequest.d.ts (2)
  • AcknowledgeOooRequest (56-61)
  • OooRequestResponse (37-37)
constants/requests.ts (3)
  • UNAUTHORIZED_TO_UPDATE_REQUEST (74-74)
  • REQUEST_ID_REQUIRED (46-46)
  • ERROR_WHILE_ACKNOWLEDGING_REQUEST (44-44)
middlewares/validators/oooRequests.ts (5)
constants/requests.ts (2)
  • REQUEST_STATE (1-5)
  • REQUEST_TYPE (13-19)
controllers/oooRequests.ts (1)
  • acknowledgeOooRequest (163-197)
services/oooRequest.ts (1)
  • acknowledgeOooRequest (142-197)
test/fixtures/oooRequest/oooRequest.ts (1)
  • acknowledgeOooRequest (170-174)
types/oooRequest.d.ts (2)
  • AcknowledgeOooRequest (56-61)
  • OooRequestResponse (37-37)
services/oooRequest.ts (6)
types/oooRequest.d.ts (3)
  • OooStatusRequestBody (21-26)
  • OooStatusRequest (7-20)
  • AcknowledgeOooRequestBody (50-54)
models/requests.ts (3)
  • createRequest (15-32)
  • getRequestById (74-85)
  • updateRequest (34-72)
constants/requests.ts (9)
  • REQUEST_TYPE (13-19)
  • INVALID_REQUEST_TYPE (71-71)
  • REQUEST_STATE (1-5)
  • REQUEST_ALREADY_APPROVED (38-38)
  • REQUEST_ALREADY_REJECTED (39-39)
  • REQUEST_LOG_TYPE (21-31)
  • REQUEST_APPROVED_SUCCESSFULLY (34-34)
  • REQUEST_REJECTED_SUCCESSFULLY (35-35)
  • LOG_ACTION (7-11)
models/userStatus.js (1)
  • addFutureStatus (678-706)
models/userFutureStatus.ts (1)
  • createUserFutureStatus (11-26)
constants/userStatus.ts (2)
  • userState (1-6)
  • statusState (8-12)
middlewares/validators/requests.ts (5)
constants/requests.ts (2)
  • REQUEST_STATE (1-5)
  • REQUEST_TYPE (13-19)
types/oooRequest.d.ts (2)
  • AcknowledgeOooRequest (56-61)
  • OooRequestResponse (37-37)
controllers/oooRequests.ts (1)
  • acknowledgeOooRequest (163-197)
middlewares/validators/oooRequests.ts (1)
  • acknowledgeOooRequest (71-84)
services/oooRequest.ts (1)
  • acknowledgeOooRequest (142-197)
🪛 ESLint
routes/requests.ts

[error] 6-6: Import in body of module; reorder to top.

(import/first)


[error] 26-26: Replace "/:id",·authenticate,·conditionalOooChecks,·updateRequestValidator,·updateRequestBeforeAcknowledgedController with ⏎··"/:id",⏎··authenticate,⏎··conditionalOooChecks,⏎··updateRequestValidator,⏎··updateRequestBeforeAcknowledgedController⏎

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)

@RealDevSquad RealDevSquad deleted a comment from coderabbitai bot Aug 29, 2025
- Removed unnecessary checks for development mode and user roles in createOooRequestController.
- Improved documentation for acknowledgeOooRequest function to clarify parameters and return types.
- Added validation for request parameters in acknowledgeOooRequest middleware.
- Updated error handling in getRequestById to use a constant for not found messages.
- Cleaned up imports in requests model to remove unused constants.
- Added role validation to ensure only users part of Discord can create OOO requests.
- Implemented a check for development mode to restrict access to the feature.
- Updated the controller to handle unauthorized access appropriately.
@AnujChhikara
Copy link
Contributor

@RishiChaubey31 please attach the working proof that user status is getting changed after approving the request

@RishiChaubey31
Copy link
Contributor Author

@RishiChaubey31 please attach the working proof that user status is getting changed after approving the request

I have added the proofs in screenshots

- Updated createOooRequestController to use username instead of roles for user identification.
- Introduced conditionalOooChecks middleware to apply role and dev checks specifically for OOO requests.
- Improved validation error handling in acknowledgeOooRequest and added constants for error messages.
- Refactored request validation schemas for clarity and consistency.
- Cleaned up imports and ensured proper middleware usage in routes.
- Removed redundant variable assignments for 'from', 'until', and 'requestedBy' in acknowledgeOooRequest function.
- Directly used the parameters in subsequent function calls to enhance code clarity and reduce unnecessary lines.
- Updated the function name from acknowledgeOooRequest to acknowledgeOooRequestController for clarity and to align with naming conventions in the codebase.
- Adjusted import statements accordingly in the requests controller to reflect the new function name.
…nability

- Added a TODO comment to indicate the need for future removal of legacy request format handling.
- Simplified the return structure by removing unnecessary data wrapping around requestResult.
- Updated requestData type assertion to include oldOooStatusRequest for better type safety.
- Removed legacy request format normalization logic to streamline the function and improve clarity.
MayankBansal12
MayankBansal12 previously approved these changes Sep 3, 2025
- Enhanced the oooRoleCheckMiddleware for better error handling and code clarity.
- Updated the acknowledgeOooRequestValidator to include specific Joi validation error handling.
- Simplified the validateOooAcknowledgeRequest function by removing unnecessary try-catch nesting and improving logging for invalid request types.
RishiChaubey31 and others added 2 commits September 5, 2025 21:55
- Updated acknowledgeOooRequestController to remove unnecessary return statement.
- Enhanced acknowledgeOooRequestValidator to streamline Joi validation error handling.
- Improved type assertions in updateRequestValidator for better clarity and type safety.
- Refined transformRequestResponse logic to simplify request transformation based on environment conditions.
* initial commit

* added-more-test

* fix-test-title

* removed-try/catch-block

* fix-try-catch-cases

* added-try-catch

* removed-functon

* test: update assertions in oooRequest tests to use include for response validation

---------

Co-authored-by: Mayank Bansal <mayankbansal125@gmail.com>
@iamitprakash iamitprakash merged commit 0f75af9 into develop Sep 6, 2025
5 checks passed
@iamitprakash iamitprakash deleted the feature/ooo-req-acknowledgement branch September 6, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement OOO acknowledgement functionality

6 participants