Periods API
This document describes the Academic Periods endpoints implemented in ILS-dev/backend/routes/periods.js. It is a read-only extraction of current server behaviour used for academic scheduling and period management.
Overview
- Purpose: manage academic periods (semesters, blocks, years, quarters, custom periods) that are used by academic calendar, timetable, and registration flows.
- Core model:
academic_periodswith fields such asname,type,start_date,end_date,institution_id,campus_id,parent_id,is_active, and soft-deletedeleted_at. - Allowed
typevalues:semester,block,year,quarter,custom.
Endpoints
- GET /api/periods
- Query params:
institution_id,campus_id,active(setactive=trueto filter active periods). -
Behaviour: returns all periods where
deleted_at IS NULLandcourse_id IS NULL(periods scoped to courses are excluded). Joins to provideparent_name,institution_name, andcampus_name. -
GET /api/periods/tree
-
Returns a nested tree of periods. The endpoint fetches matching rows and assembles parent/child relationships in-memory, returning root nodes with
childrenarrays. -
GET /api/periods/:id
-
Returns the period row with
parent_name,institution_name, andcampus_name. Returns404if not found or deleted. -
POST /api/periods
- Auth:
adminrole required (requireRole('admin')). - Body:
{ name, type='semester', start_date?, end_date?, institution_id?, campus_id?, parent_id?, is_active=true }. - Validation:
namerequired;typemust be one of the allowed types. -
Response:
201with created row. -
PUT /api/periods/:id
- Auth:
adminrole required. - Body: any of the period fields. The handler validates
typeif provided and usesCOALESCEfornameandis_activeto preserve existing values when nulls are supplied. -
Response: the updated period row or
404if not found. -
DELETE /api/periods/:id
- Auth:
adminrole required. - Behaviour: soft-delete sets
deleted_at = NOW()and returns204on success.
Implementation notes & cautions
- The list and tree endpoints exclude rows where
course_idis not NULL; these are course-scoped periods and intentionally filtered out for system-level period endpoints. - Ordering: results are ordered by
start_date NULLS LAST, nameto surface open/ongoing periods first. - Soft-delete pattern is used consistently across period APIs; clients should treat missing rows as deleted rather than absent.
Source (read-only): ILS-dev/backend/routes/periods.js
Last updated: 2026-07-08