refactor(db): add CourseRepository wrapping Course data access (#171) - #292
Conversation
…Bridge#171) Introduces mongo/repositories/CourseRepository.js extending BaseRepository so controllers/services stop querying the Course model directly. Course-specific reads: - findByEducator / paginateByEducator — courses authored by a user - findPublished — centralized, paginated public catalogue (single place to add a status filter if a draft/published lifecycle is later introduced) - searchCourses — full-text search over title/description/category with a regex fallback for short tokens - findByCategory — courses by categoryRef Enrollment queries: - findEnrolledCourses / paginateEnrolledCourses - isUserEnrolled, countEnrollments Offset pagination is provided for every listing via the inherited paginate(). ObjectId inputs are validated up front, raising the repository's typed RepositoryValidationError (HTTP 400). Adds test/courseRepository.test.js (17 cases, MongoMemoryServer).
|
@Lspnjr1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 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 |
|
Note: this branch also includes a small |
Closes #171
Summary
Adds
mongo/repositories/CourseRepository.js, extendingBaseRepository, so controllers and services stop querying theCoursemodel directly and share one typed data-access surface (consistent pagination, session support, and typed errors).What's included
Educator listings
findByEducator(educatorId, options)/paginateByEducator(educatorId, options)Catalogue discovery
findPublished(options)— centralized, offset-paginated public catalogue. The Course schema has no draft/published lifecycle field today, so this method is the single place that defines "published"; if astatus/isPublishedfield is later added, only the filter here changes.searchCourses(term, options)— full-text search overtitle/description/category(backed by the model's text index), with a case-insensitive regex fallback for short tokens that$textunder-matches.findByCategory(categoryRef, options)Enrollment queries
findEnrolledCourses(userId, options)/paginateEnrolledCourses(userId, options)isUserEnrolled(courseId, userId)— boolean membership checkcountEnrollments(courseId)Notes
paginate(); metadata (total,page,totalPages,hasNextPage…) comes for free.RepositoryValidationError(HTTP 400) instead of silently issuing a query that can never match.Tests
test/courseRepository.test.js— 17 cases on MongoMemoryServer covering educator listings, catalogue pagination + extra filters, full-text and regex-fallback search, category lookup, enrollment queries, and id validation. All green.