4.8 KiB
Assessments Backend
Purpose
assessments is the per-organization catalog of student assessments (quizzes, homework, exams,
etc.) attached to a class subject. It is a generic-CRUD slice assembled from the shared factories;
the backend is the source of truth for these records.
Slice Files (by layer)
- Route:
src/routes/assessments.ts—createCrudRouter(controller, { permission: 'assessments' }). - Controller:
src/api/controllers/assessments.controller.ts—createCrudController(service, { csvFields }). - Service (BLL):
src/services/assessments.ts—createCrudService(DbApi, { notFoundCode: 'assessmentsNotFound' }). - Repository (DAL):
src/db/api/assessments.ts(AssessmentsDBApi) — entity-specificcreate/bulkImport/update/findBy/findAll;remove/deleteByIds/findAllAutocompletedelegate todb/api/shared/repository.ts. - Model:
src/db/models/assessments.ts. - Shared used: CRUD factories (
services/shared/crud-service.ts,api/controllers/shared/crud-controller.ts,api/http/crud-router.ts), repository helpers (db/api/shared/repository.ts),shared/constants/pagination.ts(resolvePagination),db/api/file.ts(replaceRelationFilesfor theattachmentsrelation).
API
The standard generic-CRUD surface (all under /api/assessments, JWT + ${METHOD}_ASSESSMENTS
permission, all 200) — see backend-architecture.md for the shared contract:
POST /— body{ data }, returnstrue.POST /bulk-import— multipart CSV file, returnstrue.PUT /:id— body{ data, id }(the service reads the id from the body), returnstrue.DELETE /:id— returnstrue.POST /deleteByIds— body{ data: string[] }, returnstrue.GET /— query filters, returns{ rows, count };?filetype=csvstreams a CSV ofcsvFields.GET /count— returns{ rows: [], count }.GET /autocomplete—?query&limit&offset, returns[{ id, label }]wherelabelisname.GET /:id— returns the record with eager associations (see Data Contract).
csvFields: id, name, instructions, max_score, assigned_at, due_at.
Access Rules
- JWT required; the whole router is guarded by
checkCrudPermissions('assessments'), derivingREAD_ASSESSMENTS/CREATE_ASSESSMENTS/UPDATE_ASSESSMENTS/DELETE_ASSESSMENTSper HTTP method. - Access is granted by role permission or per-user
custom_permissions(seepermissions.md).
Tenant Scope
findAllscopeswhere.organizationIdtocurrentUser.organizationId; aglobalAccessrole clears the org filter (sees all tenants).createassigns the organization fromcurrentUser.organizationId;updateonly reassigns organization forglobalAccessusers (otherwise it stays the caller's org).
Data Contract
Model columns (paranoid, soft-delete via deletedAt):
id(UUID PK),name,instructions(TEXT, nullable).assessment_type— ENUMquiz|homework|project|midterm|final|other.status— ENUMdraft|published|closed.assigned_at,due_at— DATE, nullable.max_score— DECIMAL (nullable).importHash(unique),organizationId,class_subjectId,createdById,updatedById, timestamps.
Associations: belongsTo organization, class_subject (class_subjects), createdBy/updatedBy
(users); hasMany assessment_results_assessment (assessment_results); hasMany file as
attachments (scoped relation). findBy/GET /:id eager-load assessment_results_assessment,
organization, class_subject, and attachments in a single Promise.all.
List filters (AssessmentsFilter): id, name, instructions, calendarStart+calendarEnd
(matches rows whose assigned_at or due_at falls between the two), assigned_atRange,
due_atRange, max_scoreRange, active, assessment_type, status, class_subject (id or
status text, |-separated, applied as an include where-clause), organization
(|-separated ids), createdAtRange, plus field/sort ordering and limit/page
pagination.
Behavior / Notes
create/bulkImport/updatemanage theattachmentsfile relation viaFileDBApi.replaceRelationFiles.bulkImportoffsetscreatedAtper row byBULK_IMPORT_TIMESTAMP_STEP_MSto preserve order.- List pagination uses the shared
resolvePaginationdefaults (page size 10, capped at 100). - Note:
AssessmentsFilteraccepts anactiveflag the model has no column for; it is currently inert (kept for source accuracy). - Note: the
class_subjectfilter matches against the related class_subjects'statusfield for the text branch (kept for source accuracy).
Tests
None yet.
Related
- Generic-CRUD contract:
backend-architecture.md; related slices:assessment_results,class_subjects,organizations,file.md,permissions.md.