Skip to content

Comments

refactor: OOO request schema for requestedBy and userID field#2466

Merged
iamitprakash merged 1 commit intodevelopfrom
feature/user-ooo-create-requests
Aug 22, 2025
Merged

refactor: OOO request schema for requestedBy and userID field#2466
iamitprakash merged 1 commit intodevelopfrom
feature/user-ooo-create-requests

Conversation

@RishiChaubey31
Copy link
Contributor

@RishiChaubey31 RishiChaubey31 commented Aug 20, 2025

Date: 20-08-2025

Developer Name: Rishi Chaubey


Issue Ticket Number

Description

  • modified controller and service to replace userId with requestedBy for consistency
  • updated test fixtures and integration tests to reflect the change
  • ensured unit tests align with the new structure

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
creation.mp4
Screenshot 2025-08-20 120331

Test Coverage

Screenshot 1 Screenshot 2025-08-21 015919 Screenshot 2025-08-21 015705

Additional Notes

…serId

* modified controller and service to replace userId with requestedBy for consistency
* updated test fixtures and integration tests to reflect the change
* ensured unit tests align with the new structure
@coderabbitai
Copy link

coderabbitai bot commented Aug 20, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved detection of existing pending Out-of-Office requests by reliably associating them with the requester’s account ID, reducing duplicate or missed matches.
  • Chores

    • Standardized request data to consistently use the requester’s account ID for ownership, aligning stored records with authentication data.
  • Tests

    • Updated unit and integration tests to reflect the new requester identification approach and adjusted assertions accordingly.

Walkthrough

Switched OOO request identification from username-based to userId-based. Controllers now query by requestedBy:userId; service creates requests with requestedBy:userId and removes userId field. Tests and fixtures updated to reflect the new schema and expectations, including dropping a non-null assertion in an integration test.

Changes

Cohort / File(s) Summary
Controller and Service
controllers/oooRequests.ts, services/oooRequest.ts
Controller now checks existing pending OOO by { requestedBy: userId, type: OOO, status: PENDING }. Service constructs payload with requestedBy: userId and removes separate userId field. No public API signature changes.
Test Fixtures
test/fixtures/oooRequest/oooRequest.ts
Fixture updated: remove userId; set requestedBy to former userId value.
Integration Tests
test/integration/requests.test.ts
Query adjusted to use requestedBy instead of userId; removed assertion enforcing non-null retrieved request.
Unit Tests
test/unit/services/oooRequest.test.ts
Expectations updated: requestedBy equals testUserId; removed userId from expected object.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Controller as OOORequests Controller
  participant Service as OOORequest Service
  participant Repo as Requests Repo/DB

  Client->>Controller: POST /requests (OOO payload)
  Controller->>Repo: getByKeyValues({requestedBy: userId, type: OOO, status: PENDING})
  alt Pending exists
    Repo-->>Controller: Existing request
    Controller-->>Client: 409 Conflict / appropriate response
  else No pending
    Repo-->>Controller: null
    Controller->>Service: createOooRequest({from, until, reason, comment, userId})
    Service->>Repo: create({requestedBy: userId, type: OOO, status: PENDING, ...})
    Repo-->>Service: Created request
    Service-->>Controller: Created request
    Controller-->>Client: 201 Created (request)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

backend, tests

Suggested reviewers

  • AnujChhikara
  • MayankBansal12
  • prakashchoudhary07
  • iamitprakash
  • Achintya-Chatterjee

Poem

A nibble of code, a hop through IDs,
I swapped the names for user keys.
Tests now burrow where truth lies by,
RequestedBy points to userId.
Thump-thump! I merge with cheerful cheer—
My carrots align; the changes are clear. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent 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 cd129fb and 178ebb4.

📒 Files selected for processing (5)
  • controllers/oooRequests.ts (1 hunks)
  • services/oooRequest.ts (1 hunks)
  • test/fixtures/oooRequest/oooRequest.ts (1 hunks)
  • test/integration/requests.test.ts (1 hunks)
  • test/unit/services/oooRequest.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 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:

  • test/integration/requests.test.ts
  • controllers/oooRequests.ts
  • services/oooRequest.ts
  • test/unit/services/oooRequest.test.ts
  • test/fixtures/oooRequest/oooRequest.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:

  • test/integration/requests.test.ts
  • controllers/oooRequests.ts
  • test/unit/services/oooRequest.test.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:

  • test/integration/requests.test.ts
  • controllers/oooRequests.ts
  • services/oooRequest.ts
  • test/unit/services/oooRequest.test.ts
  • test/fixtures/oooRequest/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:

  • test/integration/requests.test.ts
🧬 Code Graph Analysis (1)
controllers/oooRequests.ts (2)
controllers/extensionRequests.js (1)
  • userId (149-149)
constants/requests.ts (2)
  • REQUEST_TYPE (13-19)
  • REQUEST_STATE (1-5)
🔇 Additional comments (4)
controllers/oooRequests.ts (1)

68-71: Good switch to requestedBy: userId for pending OOO lookup

This aligns the controller with the new schema and prevents username-based ambiguity.

services/oooRequest.ts (1)

69-74: Correct: requestedBy now set to userId

This matches the controller and test expectations; removing separate userId in the payload is consistent.

test/unit/services/oooRequest.test.ts (1)

93-100: Test expectation updated correctly to assert requestedBy is userId

The assertion now matches the new storage semantics (requestedBy = userId) and overrides the fixture spread appropriately.

test/integration/requests.test.ts (1)

191-194: Integration test query updated to requestedBy: userId

Good alignment with controller/model changes; asserting against reason remains valid.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/user-ooo-create-requests

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
🪧 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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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.

I've completed my review and didn't find any issues... but I did find this bear.

/  \.-"""-./  \
\    -   -    /
 |   o   o   |
 \  .-'''-.  /
  '-\__Y__/-'
     `---`
Files scanned
File Path Reviewed
services/oooRequest.ts
controllers/oooRequests.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

@MayankBansal12
Copy link
Member

@RishiChaubey31 Please fix the PR title and attach issue ticket

@RishiChaubey31 RishiChaubey31 changed the title feat: Add OOO request creation endpoint refactor: OOO request schema for requestedBy and userID field Aug 20, 2025
Copy link
Contributor

@AnujChhikara AnujChhikara left a comment

Choose a reason for hiding this comment

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

LGTM

@iamitprakash iamitprakash merged commit 3b70472 into develop Aug 22, 2025
6 checks passed
@iamitprakash iamitprakash deleted the feature/user-ooo-create-requests branch August 22, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor OOO Request Schema: Replace requestedBy with userId and Remove userId Field

5 participants