Skip to content

feat(dashboard): add instructor analytics dashboard (#562)#765

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
CNduka001:feature/562-instructor-analytics
Jun 1, 2026
Merged

feat(dashboard): add instructor analytics dashboard (#562)#765
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
CNduka001:feature/562-instructor-analytics

Conversation

@CNduka001
Copy link
Copy Markdown
Contributor

PR #562 feat(dashboard): Instructor analytics dashboard

  • Enrollment trends chart
  • Completion rate tracking
  • Revenue breakdown
  • Video watch time analytics

What changed

  • Added GET /dashboard/instructors/:instructorId endpoint in src/dashboard/dashboard.controller.ts.
  • Implemented getInstructorDashboard(instructorId) and supporting helpers in src/dashboard/dashboard.service.ts:
    • getInstructorRevenueBreakdown(instructorId) — revenue by currency, by course, and by payment method (completed payments only).
    • calculateEnrollmentTrends(courses, days=30) — daily enrollment buckets for the last 30 days (configurable).
    • calculateCompletionRate(courses) — overall and monthly completion rates (6-month window).
    • getInstructorVideoWatchTime(courses) — aggregates recorded video/watch events from analytics_events and falls back to progress-based estimates when events are absent.
  • Registered AnalyticsEvent repository in src/dashboard/dashboard.module.ts.
  • Added unit coverage in src/dashboard/dashboard.service.spec.ts to validate instructor dashboard generation and mocked query builders for payments and analytics.

API

GET /dashboard/instructors/:instructorId

Response (example):

{
  "instructorId": "instr-1",
  "revenue": { "totalRevenue": 120, "currency": "USD", "byCourse": [...], "byMethod": [...] },
  "enrollmentTrends": [{ "period": "2026-05-01", "count": 3 }, ...],
  "completionRate": { "overallRate": 0.25, "monthlyTrend": [...] },
  "videoWatchTime": { "totalWatchSeconds": 200, "byCourse": [...] },
  "courseSummary": [...],
  "generatedAt": "2026-06-01T...Z"
}

Testing

Unit tests were added/updated in src/dashboard/dashboard.service.spec.ts. To run the tests locally (project must have dev deps installed):

npm ci
npm test -- src/dashboard/dashboard.service.spec.ts --runInBand

How to smoke-test the endpoint locally

Start the application (depending on your local start script):

npm run start:dev

Then hit the endpoint (replace :instructorId with a real instructor UUID):

curl -H "Authorization: Bearer <token>" http://localhost:3000/dashboard/instructors/:instructorId

Notes for reviewers

  • The video watch time logic first queries analytics_events for category = 'video' and action = 'watch' events with a numeric value representing watched seconds. If no events exist for a course, the service estimates watch time from enrollment progress and lesson durationSeconds.
  • Revenue breakdown only considers payments with PaymentStatus.COMPLETED and uses the existing ReportingService for monthly recognition where appropriate.
  • Performance: queries join payments -> course and group by currency/course/method. If you anticipate large datasets, we should consider adding batched endpoints or pre-aggregated views.
  • Security: the controller route uses the existing DashboardService and inherits any guards on dashboard routes; consider restricting GET /dashboard/instructors/:instructorId to instructors or admins if desired.

Follow-ups

  • Add a small API DTO to shape instructor dashboard responses (optional)
  • Add pagination for byCourse revenue lists when an instructor has many courses
  • Add end-to-end tests for event-driven watch-time reporting

Files touched (high-level)

  • src/dashboard/dashboard.controller.ts
  • src/dashboard/dashboard.service.ts
  • src/dashboard/dashboard.module.ts
  • src/dashboard/dashboard.service.spec.ts

Reviewer checklist

  • Validate SQL grouping and indexes for payments and analytics_events queries (performance)
  • Confirm access restrictions for instructor dashboards
  • Verify that analytics_events contains video/watch events in expected shape before enabling the UI

Closes #562

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@CNduka001 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

@RUKAYAT-CODER
Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER RUKAYAT-CODER merged commit b860040 into rinafcode:main Jun 1, 2026
1 check failed
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.

Implement course analytics dashboard for instructors

2 participants