Skip to content

Conversation

@Sherin-2711
Copy link
Member

@Sherin-2711 Sherin-2711 commented Nov 14, 2025

Summary by CodeRabbit

  • New Features

    • Interviews endpoint supports pagination via page and limit query parameters (defaults: page 1, 10 results) and returns pagination metadata (page, limit, total, totalPages).
    • Interview records can include expanded member details (when not anonymous) for richer display.
  • Tests

    • Updated tests to validate paginated responses and the expanded interview data shape.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

The change adds pagination to getInterviews: the controller reads and validates page/limit query params (defaults 1 and 10), calls the updated service signature; the service fetches paginated interviews and total count and returns { interviews, total }; the controller responds with interviews plus pagination metadata.

Changes

Cohort / File(s) Summary
Controller & Service (pagination)
src/controllers/interview.controller.ts, src/services/interview.service.ts
Controller parses and validates page and limit (defaults 1,10); calls getInterviews(page, limit); service computes skip, runs paginated query and total count (parallel), formats interviews (omit member if anonymous) and returns { interviews, total }; response includes page, limit, total, totalPages.
Tests
tests/Interview.test.ts
Test updated to set query.page and query.limit (strings); mock getInterviews returns { interviews, total }; assertions updated for pagination fields and nested member object shape.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant Service
    participant Database

    Client->>Controller: GET /interviews?page=1&limit=10
    Controller->>Controller: parse & validate page, limit (defaults 1,10)
    Controller->>Service: getInterviews(page, limit)
    Note right of Service: compute skip = (page - 1) * limit
    par Parallel fetch
        Service->>Database: query interviews (skip, limit, include member)
        Service->>Database: count total interviews
    and
        Database-->>Service: interviews[]
        Database-->>Service: total
    end
    Service->>Service: format interviews (omit member if anonymous)
    Service-->>Controller: { interviews, total }
    Controller->>Controller: compute totalPages = ceil(total / limit)
    Controller-->>Client: { success, data: { interviews, page, limit, total, totalPages } }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • Review controller validation and error responses for invalid page/limit.
  • Verify service default params, skip calculation, and parallel DB queries.
  • Check formatting logic for anonymous vs. populated member fields.
  • Ensure tests correctly mock the new return shape and cover total=0 edge case.

Possibly related PRs

Suggested reviewers

  • Harish-Naruto
  • i-am-that-guy

Poem

🐇 I hop through pages, one and ten,

Skipping rows with a twitch of my pen,
Counting totals, neat and sweet,
Returning lists for each new seat,
A rabbit's pagination, quick and zen.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Interview pagination' accurately summarizes the main change in the changeset, which implements pagination functionality for the getInterviews endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch interview-pagination

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c711b5 and b2165f6.

📒 Files selected for processing (1)
  • src/controllers/interview.controller.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/controllers/interview.controller.ts

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.

Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea2ffee and 6b2b63f.

📒 Files selected for processing (3)
  • src/controllers/interview.controller.ts (1 hunks)
  • src/services/interview.service.ts (1 hunks)
  • tests/Interview.test.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/services/interview.service.ts (2)
src/controllers/interview.controller.ts (1)
  • getInterviews (5-19)
src/services/member.service.ts (1)
  • getInterviews (142-146)
tests/Interview.test.ts (1)
src/controllers/interview.controller.ts (1)
  • getInterviews (5-19)
🪛 ESLint
src/services/interview.service.ts

[error] 28-28: 'memberId' is defined but never used.

(@typescript-eslint/no-unused-vars)

tests/Interview.test.ts

[error] 8-8: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

⏰ 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: test
🔇 Additional comments (5)
src/services/interview.service.ts (3)

3-4: LGTM! Pagination setup is correct.

The function signature with default parameters and skip calculation follows standard pagination patterns.


6-25: LGTM! Efficient parallel data fetching.

Using Promise.all to fetch interviews and total count concurrently is a good performance optimization. The member relation and ordering are appropriately configured.


27-31: LGTM! Privacy-conscious data formatting.

The formatting logic correctly excludes memberId when including the full member object, which is the intended behavior. The unused variable warning from ESLint is a false positive—memberId is destructured specifically to exclude it from the spread operation.

tests/Interview.test.ts (1)

8-54: LGTM! Tests properly updated for pagination.

The test correctly mocks the paginated response structure and validates all pagination metadata fields. The nested member object in the mock data aligns with the service layer changes.

src/controllers/interview.controller.ts (1)

9-18: LGTM! Pagination response structure is correct.

The service call and response formatting properly implement pagination with all necessary metadata fields. The totalPages calculation is correct, assuming input validation is added to prevent division by zero.

i-am-that-guy
i-am-that-guy previously approved these changes Nov 16, 2025
@i-am-that-guy
Copy link
Member

@Harish-Naruto Please review once

Copy link
Contributor

@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: 1

🧹 Nitpick comments (1)
src/controllers/interview.controller.ts (1)

6-7: The isNaN checks are technically unreachable.

Since parseInt returns NaN for invalid inputs and the || 1 (or || 10) operator converts NaN to the default value, page and limit can never be NaN by the time they reach the validation checks on lines 9 and 12. The isNaN checks are defensive but unreachable.

If you prefer cleaner code, you can remove the isNaN checks:

-  if(isNaN(page) || page<1){
+  if(page < 1){
     throw new ApiError("Page must me greater than or equal to 1",400);
   }
-  if(isNaN(limit) || limit<1 || limit>100){
+  if(limit < 1 || limit > 100){
     throw new ApiError("Limit must me between 1 to 100",400)
   }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b2b63f and 5c711b5.

📒 Files selected for processing (1)
  • src/controllers/interview.controller.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/controllers/interview.controller.ts (1)
src/utils/apiError.ts (1)
  • ApiError (6-17)
🔇 Additional comments (2)
src/controllers/interview.controller.ts (2)

16-16: LGTM!

The service call correctly passes pagination parameters and properly destructures the response.


18-25: LGTM!

The pagination response structure is well-designed:

  • Includes all necessary pagination metadata (page, limit, total, totalPages)
  • The Math.ceil(total / limit) calculation is safe since limit is validated to be >= 1
  • Maintains backward compatibility with existing success and data fields

@Harish-Naruto Harish-Naruto merged commit 0a91c6b into main Nov 17, 2025
2 checks passed
@Harish-Naruto Harish-Naruto deleted the interview-pagination branch November 17, 2025 07:17
This was referenced Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants