Skip to content

refactor(db): add CourseRepository wrapping Course data access (#171) - #292

Merged
zeemscript merged 1 commit into
Deen-Bridge:devfrom
Lspnjr1:fix/issue-171
Aug 24, 2026
Merged

refactor(db): add CourseRepository wrapping Course data access (#171)#292
zeemscript merged 1 commit into
Deen-Bridge:devfrom
Lspnjr1:fix/issue-171

Conversation

@Lspnjr1

@Lspnjr1 Lspnjr1 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Closes #171

Summary

Adds mongo/repositories/CourseRepository.js, extending BaseRepository, so controllers and services stop querying the Course model 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 a status/isPublished field is later added, only the filter here changes.
  • searchCourses(term, options) — full-text search over title/description/category (backed by the model's text index), with a case-insensitive regex fallback for short tokens that $text under-matches.
  • findByCategory(categoryRef, options)

Enrollment queries

  • findEnrolledCourses(userId, options) / paginateEnrolledCourses(userId, options)
  • isUserEnrolled(courseId, userId) — boolean membership check
  • countEnrollments(courseId)

Notes

  • Every listing supports offset pagination via the inherited paginate(); metadata (total, page, totalPages, hasNextPage…) comes for free.
  • ObjectId inputs are validated up front and raise the repository's typed RepositoryValidationError (HTTP 400) instead of silently issuing a query that can never match.
  • Purely additive — no existing files modified.

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.

…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).
@drips-wave

drips-wave Bot commented Aug 24, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0c83b061-8639-49a4-8005-3e4e4196e87b


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.

@zeemscript
zeemscript merged commit f280125 into Deen-Bridge:dev Aug 24, 2026
1 of 3 checks passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Aug 24, 2026
4 tasks
@Lspnjr1

Lspnjr1 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Note: this branch also includes a small chore commit that regenerates package-lock.json to match package.json. On dev, the lockfile is missing swagger-ui-express/js-yaml@4 and their @types (added by the API playground PR #277 without regenerating the lock), so npm ci currently fails for every PR to dev. The lock-only regeneration (no runtime dependency changes) unblocks the Run Tests and Syntax-and-Boot-Check jobs. Happy to split it into its own PR if you'd prefer.

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.

2 participants