-
Notifications
You must be signed in to change notification settings - Fork 5
Interview pagination #50
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
Conversation
WalkthroughThe 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 Changes
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 } }
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. Comment |
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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.allto 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
memberIdwhen including the fullmemberobject, which is the intended behavior. The unused variable warning from ESLint is a false positive—memberIdis 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
memberobject 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
totalPagescalculation is correct, assuming input validation is added to prevent division by zero.
|
@Harish-Naruto Please review once |
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: 1
🧹 Nitpick comments (1)
src/controllers/interview.controller.ts (1)
6-7: TheisNaNchecks are technically unreachable.Since
parseIntreturns NaN for invalid inputs and the|| 1(or|| 10) operator converts NaN to the default value,pageandlimitcan never be NaN by the time they reach the validation checks on lines 9 and 12. TheisNaNchecks are defensive but unreachable.If you prefer cleaner code, you can remove the
isNaNchecks:- 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
📒 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 sincelimitis validated to be >= 1- Maintains backward compatibility with existing
successanddatafields
Summary by CodeRabbit
New Features
Tests