Skip to main content

Enrollment Module

Location: backend/src/enrollment/

The enrollment module handles two key operations:

  1. Student Enrollment - adding/removing students from a class
  2. Subject Assignment - assigning subjects to individual students within a class

Files

FilePurpose
enrollment.module.tsModule definition; imports ClassModule for ClassTeacherGuard
enrollment.controller.tsAPI endpoints under classes/:classId
enrollment.service.tsBusiness logic
dto/enroll-student.dto.tsSingle student enrollment
dto/bulk-enroll.dto.tsBulk student enrollment
dto/assign-subjects.dto.tsSubject assignment for one student
dto/bulk-assign-subjects.dto.tsBulk subject assignment

Data Model

Student Group Enrollment (student schema)

FieldTypeDescription
idUUIDPrimary key
student_idUUIDThe student
student_group_idUUIDThe class
enrolled_attimestampWhen the student was enrolled

Student Subject Profile (student schema)

FieldTypeDescription
idUUIDPrimary key
student_idUUIDThe student
subject_idUUIDThe subject
academic_year_idUUIDThe academic year

Access Control

The enrollment controller splits access between read and write operations:

OperationGuardWho Can Access
View enrolled studentsAuthGuard onlyAny teacher assigned to the class
View student subjectsAuthGuard onlyAny teacher assigned to the class
Enroll/unenroll studentsAuthGuard + ClassTeacherGuardClass teacher or admin only
Assign/remove subjectsAuthGuard + ClassTeacherGuardClass teacher or admin only

Student Visibility Rules

The getEnrolledStudents method applies role-based filtering:

RoleStudents Visible
AdminAll enrolled students
Class TeacherAll enrolled students
Subject TeacherOnly students assigned to at least one subject that the teacher teaches in this class

Additionally, the response includes a subjects array on each student showing their assigned subject names and codes. For subject teachers, this is limited to subjects they teach.

API Endpoints

All endpoints are nested under classes/:classId and require AuthGuard.

GET /api/classes/:classId/students

Returns enrolled students with their assigned subjects.

Query Parameters:

ParamRequiredDescription
subjectIdNoFilter to students assigned to a specific subject

The subjectId parameter is used by the grading page to only show students who take the subject being graded.

Response:

[
{
"id": "enrollment-uuid",
"enrolled_at": "2025-09-01T00:00:00Z",
"student": {
"id": "student-uuid",
"first_name": "Jane",
"last_name": "Doe",
"gender": "female",
"date_of_birth": null,
"is_active": true
},
"subjects": [
{ "id": "uuid", "name": "Mathematics", "code": "MATH" },
{ "id": "uuid", "name": "Language Arts", "code": "ENG" }
]
}
]

GET /api/classes/:classId/students/:studentId/subjects

Returns the subjects assigned to a specific student, with full subject details.


POST /api/classes/:classId/enroll

Requires: ClassTeacherGuard

Enrolls a single student.

Body:

{ "studentId": "uuid" }

Error: 409 Conflict if already enrolled.


POST /api/classes/:classId/enroll/bulk

Requires: ClassTeacherGuard

Enrolls multiple students at once.

Body:

{ "studentIds": ["uuid1", "uuid2", "uuid3"] }

DELETE /api/classes/:classId/enroll/:studentId

Requires: ClassTeacherGuard

Unenrolls a student. Also deletes all their subject assignments for the academic year.


POST /api/classes/:classId/subjects

Requires: ClassTeacherGuard

Assigns subjects to a student.

Body:

{
"studentId": "uuid",
"subjectIds": ["uuid1", "uuid2"]
}

POST /api/classes/:classId/subjects/bulk

Requires: ClassTeacherGuard

Assigns subjects to multiple students at once.

Body:

{
"studentIds": ["uuid1", "uuid2"],
"subjectIds": ["uuid1", "uuid2"]
}

Creates a subject profile for every combination of student × subject.


DELETE /api/classes/:classId/students/:studentId/subjects/:subjectId

Requires: ClassTeacherGuard

Removes a subject from a student. Fails with 409 Conflict if the student has existing grades for that subject (foreign key constraint).