Naalya Handbook
School features

Templates

Admin-authored Tiptap document templates for lesson planning, school-owned or platform built-ins, validated against a single editor schema.

A template is a pre-built Tiptap document a teacher instantiates instead of starting blank: "Term Scheme of Work", "Standard Lesson Plan". Two kinds share one table, split by a single column: school templates are ordinary tenant rows, while platform built-ins have schoolId IS NULL, are visible to every school, and are managed only by platform operators. That one nullable column does the work a whole second table would otherwise do.

ColumnNotes
schoolId (nullable)NULL = platform built-in, visible everywhere
typescheme_of_work, lesson_plan, or record_of_work (TemplateType). It must match the document being created from it
statusdraft / published, only published templates can be instantiated
content / contentHtmlThe Tiptap doc + server-rendered HTML projection

One editor schema, everywhere

editor/editor-schema.ts is the single source of truth for what any document in the lesson-planning family may contain:

  • EDITOR_EXTENSIONS = Tiptap StarterKit (paragraphs, headings, lists, blockquote, code block, link, underline, bold/italic/strike...) plus non-resizable tables.
  • The allowed node and mark lists are derived from those extensions via getSchema(EDITOR_EXTENSIONS), not hand-maintained. Add an extension and the allowlist grows with it; there is no second list to forget.

editor/tiptap-content.ts then enforces it on every write, in template, scheme, and lesson-plan services alike:

  • validateTiptapContent: root must be type: 'doc', the doc must fit 1 MiB (MAX_CONTENT_BYTES), and a full tree walk rejects any node or mark type outside the allowlist, an unknown type is a 400, not a silently-stored surprise.
  • renderContentHtml renders the HTML projection server-side with the exact same extensions (@tiptap/static-renderer), which is why contentHtml can be trusted as a faithful, XSS-bounded rendering of the JSON.
  • EMPTY_TIPTAP_DOC ({ type: 'doc', content: [{ type: 'paragraph' }] }) is the canonical blank.

Change the backend schema and the Education Hub toolbar together

The Education Hub editor's toolbar must offer exactly what EDITOR_EXTENSIONS allows: the schema file's own comment says so. Add a Tiptap extension on one side without the other and users either lose a button or get their content rejected at save.

Instantiation

resolveForInstantiation(templateId, expectedType) is the one door consumers use. The callers are SchemeOfWorkService.create (TemplateType.SCHEME_OF_WORK), LessonPlanService.create (TemplateType.LESSON_PLAN), and RecordOfWorkService.create (TemplateType.RECORD_OF_WORK). See Lesson Planning. Three checks: the template must be visible (own school, or a built-in), published (drafts can't be instantiated), and type-matched (a scheme can't start from a lesson-plan template). The consumer then copies content + contentHtml and stamps sourceTemplateId: a copy, not a reference, so documents keep their provenance and their content even if the template is later edited or soft-deleted.

School routes

TemplateController is /api/v1/templates. The class requires the lesson-planning feature and a staff token. Writes also require MANAGE on TEMPLATE. List and get have no permission decorator. The service builds a staff ability and calls hasManage because those reads would otherwise have no request ability.

Create body: type (the template enum), name (required, at most 255 characters), optional description (at most 1000), optional Tiptap content. A missing document becomes EMPTY_TIPTAP_DOC. The row is stored as draft. An invalid document fails the IsTiptapDocument check before the service runs.

Method and pathoperationIdWhoResult
POST /templatescreateTemplateManage template201. A draft. Audited as a template create.
GET /templateslistTemplatesStaffCursor page. Search uses the name column.
GET /templates/:idgetTemplateStaffThe row, including content.
PATCH /templates/:idupdateTemplateManage template200. Content writes go through the collab document named template plus the id.
POST /templates/:id/publishpublishTemplateManage template200. Sets published and publishedAt. Already published returns the row.
POST /templates/:id/unpublishunpublishTemplateManage template200. Sets draft and clears publishedAt. Already draft returns the row.
DELETE /templates/:iddeleteTemplateManage template{ "message": "Template deleted successfully" } after a soft delete and closing that collab document.
CallerList showsGet a school draft
Has MANAGE on TEMPLATEOwn school's rows at the requested status, plus published built-ins (unless only drafts were asked for)Allowed
No managePublished school rows and published built-ins; a draft filter returns an empty pageYou do not have access to this template
WhenMessage
Missing row, a built-in id on school mutation routes, or a built-in draft on getTemplate not found
No school on the tenant contextNo school context
Instantiating a missing or unpublished templateTemplate not found
Instantiating with the wrong typeTemplate type does not match the document being created

Update accepts name, description, Tiptap content, orientation and brandHeader. An empty patch returns the row without emitting the update invalidation.

Example Secondary School can keep a draft Term Scheme of Work and publish it when ready. A teacher starting a scheme receives a copy, which stays even if the template is unpublished.

Platform routes

PlatformTemplateController (/api/v1/platform/templates) needs platform_admin and MANAGE on TEMPLATE, with no lesson-planning feature check. Every method pins schoolId to null; list returns built-ins of any status. Bodies, messages and idempotent publish and unpublish match the school routes. Unlike school create, createBuiltIn emits no realtime invalidation.

The Hub screen staff-hub/school/templates/index.tsx needs the lesson-planning feature and MANAGE on TEMPLATE. New template (wrapped in CREATE) offers Scheme of work, Lesson plan and Record of work, omits a blank description, toasts Template created and opens the new template. Task steps are on Manage templates.

Where to go next

On this page