Open enrollment and late joiners
Edition enrollment window (one rule for backend and web-next), unlimited seats, recalculated instalments for late joiners, the academic year setting, Before enrollment / To catch up in the attendance registry: data model, rules, migration, tests.
Status: branch feat/open-enrollment (07/10/2026). Owner decision of 07/10. Guides: Selling a course, Academic years, Attendance registry. Paths relative to backend/ and web-next/.
1. Data model
| Where | Field | Meaning |
|---|---|---|
courses.cycles[] and course_revisions.cycles[] (course-cycle.model.ts) | openEnrollment?: boolean | The edition's Open enrollment. Missing = off (older editions). New editions start with true (CourseCyclesDto.fromMoments, fromCreateCourseRequest; the builder can send false). |
| same | catchUpRequired?: boolean | Past lessons must be caught up. Missing = off. |
academic_years | openEnrollment?: boolean | The year's setting (missing = on): preparation writes it on each edition's cycle (CourseEditionsService.applyYearSettings). |
course_members.cycle[] | enrolledAt?: Date | When the student joined the edition (purchase and external enrollment on an existing member). Missing = the member's createdAt. No schema default: cycle $addToSets compare the whole element. |
Edition settings apply to every version of the course: they are written with a targeted $set (cycles.$[cycle].… with arrayFilters) on the course and all its revisions (CourseCyclesService.applyCycleSettings), like seats sold; the cycle mappers (CourseCycle, CourseCyclesDto, CourseCyclesRto, UpdateCourseCyclesDto, buildCyclePayload, validateAndReorderCycles) carry them, so a date change doesn't drop them. Endpoint: PATCH /courses/:id/cycles/:cycleId/settings { openEnrollment?, catchUpRequired? } (also on published editions, no CourseStatusGuard); POST /courses/:id/cycles accepts openEnrollment.
Seats: no per-edition seatCount. editionSeatCount(course.seatCount, cycle) = -1 with open enrollment, otherwise the course seatCount (-1, 0 or missing = unlimited). The "previous" value needs no storage: the course seatCount is never touched.
2. Enrollment window (one rule)
libs/common/src/common/enrollment/enrollment-window.rules.ts, twin web-next/lib/enrollment-window.ts (same names): dayIn, editionPhase (before-start / open-started / started / ended), editionAvailability (reason: ended > started > sold-out), firstAvailableEdition, closedReasonOf. Days in the buyer's time zone (backend: the profile timezone or the one sent by the guest checkout; web-next: the browser).
| Point | Use |
|---|---|
CheckoutValidationService (payment) | assertEditionAvailable → cycle-ended / cycle-start-date-in-past / course-cycle-seats-full / purchase-quantity-exceeded-available-seats; getFirstAvailableCycleId. Invitations: validateInvitationCycle as before. |
CheckoutDto.fromProfileGatewayRequest, guest checkout gateway/payment | default edition = firstAvailableEdition (before: cycles[0]). |
CoursesSeatCountService.getFirstAvailableCycleId | same rule for the reserved seat. |
handleFreeCourseStarted, create (free course) | assertEditionOpen (apps/course/.../enrollment-window.guard.ts). |
enrollExternal (API, "Enroll" in Requests) | only for a NEW enrollment in the edition, dates yes, seats no; SSO excluded. Non-strict enrollmentCycleOf picks the first open edition. |
| web-next | cycleOptions/purchasability/defaultCycleId (lib/course-purchase.ts), "Enrollment closed" in purchase-box.tsx, EditionClosedState in both checkouts with closedReasonOfError. |
| web-next, label | editionLabel / editionLabelText / isOpenEnrollmentLabel (web-next only): open / open-started / seats-left / unlimited / sold-out / closed / ended. With open enrollment the Open enrollment badge (or In progress · enrollment open) replaces the seats: CycleOption.label (course page, PurchaseBar, purchase dialog) and the Start dates popover in course-cycles-badge.tsx (card, showcase, builder preview). |
3. Instalments for late joiners
libs/common/src/common/payments/late-enrollment.rules.ts (latePlanOf, planShapeOf, firstDueOf), twin in web-next/lib/guest-checkout.ts (latePlanOf, latePlanFor, euro unit). Plan due dates = installments.dates + lastInstallment.date; future = day > today (buyer's time zone). All future → plan unchanged (recalculated: false). Rest = remainingAmount (or the sum of the instalments), round(rest / n) with the remainder on the last one. None future → singlePaymentOnly.
- Standard (
DirectInstallmentsService.startPlan): phases fromlatePlanOfwithpurchasedAt = session.createdandtimeZone = metadata.timezone(set byDirectCheckoutService). - Platform:
ProductsService.buildLateEnrollmentSubscriptionInfo→ new Prices andSubscriptionInfo.fromInvitation, passed like invitation info tocreateCheckoutSession. - Validation:
validateLateInstallments→single-payment-option-requiredwhen no instalment is left. - Preview (
InstallmentsPreviewService): recalculated rows,lateEnrollment: { recalculated, singlePaymentOnly }, cache per day and time zone. web-next:laterRows, purchase dialog, single payment forced in the guest checkout.
4. Attendance registry
libs/common/src/common/attendance/late-enrollment-attendance.rules.ts: enrollmentDateOf, isBeforeEnrollment (lesson ended before), recoveryDeadline (from the lesson, or from the enrollment if later), lateEnrollmentStatus. New AttendanceRecordStatus values: pre-enrollment, to-recover — computed on read, never stored (STORED_ATTENDANCE_STATUSES in the model and the manual DTO), no job.
AttendanceService.registry: rowsvirtual: true, beforeEnrollment: true+enrollments(ISO per student) +catchUpRequired; a decided stored row (present/late/remote/excused or locked) wins, an automaticabsentbefore the enrollment doesn't.summarize:preEnrollmentoutsidetotal,toRecoverinside,recovered= remote before the enrollment.recordFromRecording: deadline withrecoveryDeadline(lecture, days, enrolledAt).- Certificate:
CompletionRetrievalService.beforeEnrollmentLectureIdsdrops from the average lessons before the enrollment not caught up (progress 0), unlesscatchUpRequired. - Students table (aggregated index): counts stored rows only, so lessons before the enrollment already don't weigh.
- web-next:
RegistryStatus,STATUS_STYLE(pre-enrollmentgrey,to-recoverorange),addToBreakdown,lateSummary,lib/lesson-bar.ts.
Visibility for late joiners: checked, no change. COURSE_MEMBER_ADDED → calendar-member-upsert.service.ts adds the member to ALL events of the edition calendar (past ones too); lessons and recordings are filtered by edition and membership only.
5. Migration
scripts/migrations/2026-10-open-enrollment.js (PHASE=plan counts per organization only; ONLY required with apply): turns openEnrollment on for the cycles of academic-year editions without the field (course + revisions, backup in _bak_202610_open_enrollment_*) and on years without the setting. The Owner decides the apply.
6. Tests
tests/unit/enrollment-window.spec.ts: window with/without open enrollment, last day, time zone, unlimited seats and restore, real reason, first open edition, invitations, enrollments without payment, cycle mappers.tests/unit/late-enrollment.spec.tsanddirect-installments.spec.ts: different enrollment dates, today's instalment, rounding, no future due date, Stripe phases.tests/unit/late-enrollment-attendance.spec.ts: before enrollment, catch-up and deadline, option, percentage, registry, certificate average.tests/unit/academic-year-versions.spec.ts: the year setting on the cycle.- web-next
node --test:lib/enrollment-window.test.mjs,lib/guest-checkout.test.mjs,lib/lesson-bar.test.mjs.