Skip to content

FAC-119 fix: correct semester year derivation and add category preview endpoint #283

@y4nder

Description

@y4nder

Problem

Two bugs in Moodle category provisioning plus a missing safety feature:

  1. Wrong semester tag generation: ProvisionCategories extracted year values via .slice(2, 4) on startDate/endDate without accounting for the academic year. When a single semester is selected (dates fall in the same calendar year), this produces wrong tags — e.g., S22626 instead of S22526 for semester 2 of school year 2025-2026.

  2. Unhelpful error on webservice_access_exception: The Moodle client threw a generic error with no guidance on how to fix the permission issue.

  3. No category preview: Unlike courses, category provisioning went straight to execution with no preview step.

Solution

  • Add ComputeSchoolYears() to MoodleCourseTransformService for school-year-aware startYY/endYY computation
  • Replace static year extraction in ProvisionCategories with per-semester ComputeSchoolYears calls
  • Improve webservice_access_exception error with actionable hint
  • Add POST /moodle/provision/categories/preview endpoint (read-only, no concurrency guard)
  • Add error wrapping to existing ProvisionCategories endpoint (consistency with tree endpoints)

Files Changed

  • src/modules/moodle/services/moodle-course-transform.service.ts
  • src/modules/moodle/services/moodle-course-transform.service.spec.ts
  • src/modules/moodle/services/moodle-provisioning.service.ts
  • src/modules/moodle/services/moodle-provisioning.service.spec.ts
  • src/modules/moodle/lib/moodle.client.ts
  • src/modules/moodle/lib/moodle.client.spec.ts (new)
  • src/modules/moodle/controllers/moodle-provisioning.controller.ts
  • src/modules/moodle/controllers/moodle-provisioning.controller.spec.ts

Testing

  • 59 tests passing across 4 suites (27 new)
  • Frontend admin console changes in separate admin.faculytics repo

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions