Skip to content

Add bulk course enrollment API endpoint with transaction wrapper #841

Description

@RUKAYAT-CODER

Overview

Admins and instructors currently enroll students one at a time via individual API calls. Enrolling a cohort of 500 students requires 500 sequential requests, is slow, and risks partial failure leaving students in inconsistent enrollment states.

Specifications

Features:

  • POST /enrollments/bulk accepts an array of { userId, courseId } pairs.
  • Entire batch succeeds or fails atomically inside a database transaction.

Tasks:

  • Create BulkEnrollmentDto with @ArrayMaxSize(500) validation.
  • Implement EnrollmentsService.bulkEnroll() using TypeORM QueryRunner transaction.
  • Return a summary: { enrolled: N, skipped: N, failed: N, errors: [] }.
  • Add rate limiting on the bulk endpoint (max 1 request/minute per user).
  • Add integration tests for partial failure rollback.

Impacted Files:

  • src/courses/enrollments/ (service and controller)

Acceptance Criteria

  • Partial validation failure rolls back all enrolled records.
  • Response includes per-item error details for skipped records.
  • Bulk enroll 500 users in under 2 seconds.

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions