getActiveRegistration method

Future<UserRegistration?> getActiveRegistration()

Gets the user's active registration (where enrollment status is "在學").

Returns the most recent semester where the user is actively enrolled, or null if no active registration exists. Pure DB read — call getUser first to populate registration data.

Implementation

Future<UserRegistration?> getActiveRegistration() async {
  return (_database.select(_database.userRegistrations)
        ..where(
          (r) => r.enrollmentStatus.equalsValue(EnrollmentStatus.learning),
        )
        ..orderBy([
          (r) => OrderingTerm.desc(r.year),
          (r) => OrderingTerm.desc(r.term),
        ])
        ..limit(1))
      .getSingleOrNull();
}