CBT operations
The HTTP methods on the student, examination, stream, and question controllers, and the order a sitting actually uses.
Prefix every path below with /api/v1. None of these controllers use @RequirePermissions. Staff routes require user type staff. The student controller requires user type student. Every class requires Feature.CBT. The decorators are not the access check. CbtAccessService and CbtStudentAccessService throw the failures below. None of these routes were called.
The generate, extract, and CSV import flow is on Generate and import questions. CbtQuestionGenerateController is not HTTP. It handles two RabbitMQ patterns, CBT_QUESTION_GENERATE_BRIEF_PATTERN and CBT_QUESTION_GENERATE_APPLY_PATTERN. The comment says authorization already happened when the job was queued.
A sitting, as the routes are wired
- Staff
POST /cbt/examinationscreates a draft (createCbtExamination, 201CbtExaminationDto). - Staff add questions on
/cbt/examinations/:examinationId/questionswhile the exam is still a draft. The add, update, reorder, and delete operation texts say draft. - Staff
POST /cbt/examinations/:id/publish(publishCbtExamination). The text says publish fails unless the exam has questions, every question has marks, and per-question timing is complete. - Staff
POST /cbt/examinations/:examinationId/streams(assignCbtExaminationStream) sets that stream’s window and attempt cap. The text says the exam must already be published. - A student
GET /cbt/student/examinations(listMyCbtExaminations) lists published exams they are eligible for. POST /cbt/student/examinations/:examinationId/attempts(startCbtAttempt, 201) starts or resumes. The text says it fails when attempts are exhausted.PUT /cbt/student/attempts/:attemptId/answers/:questionId(saveCbtAnswer) upserts one answer. Body isSaveCbtAnswerDto. Field constraints were not copied.POST /cbt/student/attempts/:attemptId/submit(submitCbtAttempt, HTTP 200) submits. The text says a second call returns the terminal attempt unchanged.- Staff
PUT /cbt/examinations/:examinationId/attempts/:attemptId/grades(saveCbtGrades) stores draft marks.POST .../finalise(finaliseCbtAttempt, HTTP 200) sets statusgradedinCbtGradingService.finalizeAttempt.POST .../voidandPOST .../reopenare the other two staff writes. Their service behaviour is the next section.
Who may touch an exam
CbtAccessService resolves the caller’s staff profile and throws NotFoundException Staff profile not found when there is none. Teaching rows are keyed by that profile id.
| Method | Passes when | Otherwise |
|---|---|---|
assertCanCreateForSubject | Any SubjectXTeacher row for that subject, or campus-scoped create on cbt_exam | You do not teach this subject |
assertCanManageExamFor | A teaching row for the subject, narrowed to streamId or classId when the target has one. With neither, any row for the subject is enough. Otherwise campus-scoped manage on cbt_exam, unless the caller passes another action | You do not teach this subject for this class |
assertCanReadExam | Owner, or teaches the subject, or is class teacher of a stream the exam is assigned to, or campus-scoped read on cbt_exam | You do not have access to this examination |
assertCanAssignStream | Owner, or teaches that subject on that stream, or campus-scoped manage | You do not own this exam and do not teach this subject for the stream |
The permission fallback calls PermissionScopeService.assertCanAccess and treats any throw as “no”. A fragment of loadManageableExam calls assertCanManageExamFor with { subjectId: exam.subjectId } and the exam’s campus. That object has no class or stream, so any teaching row for the subject passes. The action argument was cut off in the fragment. CbtGradingService calls loadManageableExam with Action.UPDATE before save, finalise, void, and reopen. Whether that action is forwarded was not in the fragment.
A student is a different service. CbtStudentAccessService.resolveStudentProfile throws Student profile not found. assertEligible throws Exam term not found when the term row is missing, and This exam is not assigned to your stream when no active enrollment for that year both takes the subject (endedAt null) and has a stream assignment for the exam. assertOwnsAttempt throws This attempt does not belong to you.
Void and reopen
Both start with loadManageableExam and Action.UPDATE, then load the attempt. A missing attempt, or one whose examinationId does not match, is NotFoundException Attempt not found.
voidAttempt allows only submitted, expired, or graded. Anything else, including in_progress and voided, throws Only a submitted, expired, or graded attempt can be voided. The controller’s OpenAPI text says “Attempt cannot be voided.” That string is the decorator. The exception the service throws is the longer sentence. If the attempt was graded, clearFromCbtAttempt runs before the status change. The update sets voided, and sets finalScore, gradedAt, and gradedById to null. Answer rows are not deleted. The comment says they are kept so a reopen can grade again.
reopenAttempt throws Only a voided attempt can be reopened unless status is voided. The OpenAPI text “Attempt cannot be reopened.” is the decorator, not this exception. The update sets status submitted and does not restore finalScore. It does not call the gradebook sync.
finalizeAttempt uses the same gradable set and throws Only a submitted, expired, or graded attempt can be graded otherwise. It sums awardedMarks, sets graded, gradedAt, and gradedById to the staff profile id, then syncFromCbtAttempt. Marks outside 0..question.marks throw awardedMarks ... is out of range. A question id that is not on the exam throws Question ... does not belong to this exam.
Lazy expiry and submit are on Student runtime and grading. Submit of an in_progress attempt stores submitted even after expiresAt. getAttempt and saveAnswer are what store expired.
Student
Controller CbtStudentController, prefix cbt/student.
| Method and path | operationId | Success |
|---|---|---|
GET /examinations | listMyCbtExaminations | 200, array of CbtEligibleExaminationDto |
POST /examinations/:examinationId/attempts | startCbtAttempt | 201, StartCbtAttemptResponseDto |
GET /attempts/:attemptId | getCbtAttempt | 200, GetCbtAttemptResponseDto. The text says an expired attempt is finalised lazily here |
PUT /attempts/:attemptId/answers/:questionId | saveCbtAnswer | 200. The text says a closed, expired, or other student’s attempt fails |
POST /attempts/:attemptId/submit | submitCbtAttempt | 200, CbtAttemptDto |
POST /attempts/:attemptId/events | recordCbtProctorEvents | 200, RecordCbtProctorEventsResponseDto. Body events. The text says duplicates of clientEventId are ignored |
POST /attempts/:attemptId/recordings | createCbtRecordingChunk | 200, presigned upload. The text says only while the attempt is in progress and recording is enabled |
POST /attempts/:attemptId/recordings/:chunkId/confirm | confirmCbtRecordingChunk | 200 |
Path ids on this controller are not ParseUUIDPipe in the signatures that were read.
Examinations
Controller CbtExaminationController, prefix cbt/examinations, user type staff.
| Method and path | operationId | Success the decorator names |
|---|---|---|
POST / | createCbtExamination | 201 CbtExaminationDto |
GET / | listCbtExaminations | 200 CbtExaminationListResponseDto (cursor) |
GET /:id | getCbtExamination | 200 CbtExaminationDto. 404 “Examination not found.” |
PATCH /:id | updateCbtExamination | 200. The text says subject, class, stream, and term cannot change |
POST /:id/publish | publishCbtExamination | 200 |
POST /:id/close | closeCbtExamination | 200 |
DELETE /:id | deleteCbtExamination | 200 { "message": "Examination deleted successfully" }. 400 “Students have unfinished attempts on this examination.” |
GET /:examinationId/attempts | listCbtAttempts | 200 array of CbtStaffAttemptDto |
GET /:examinationId/attempts/:attemptId | getCbtAttemptForStaff | 200 CbtAttemptForGradingResponseDto. Includes awardedMarks and isCorrect |
GET /:examinationId/attempts/:attemptId/events | listCbtProctorEvents | 200. The handler is audit-logged as a view |
GET /:examinationId/attempts/:attemptId/recordings | listCbtRecordingChunks | 200. Also audit-logged as a view |
PUT /:examinationId/attempts/:attemptId/grades | saveCbtGrades | 200. Body SaveCbtGradesDto |
POST /:examinationId/attempts/:attemptId/finalise | finaliseCbtAttempt | 200 CbtStaffAttemptDto. Body FinalizeCbtAttemptDto |
POST /:examinationId/attempts/:attemptId/void | voidCbtAttempt | 200. Service 400 Only a submitted, expired, or graded attempt can be voided. The decorator text is shorter |
POST /:examinationId/attempts/:attemptId/reopen | reopenCbtAttempt | 200. Service 400 Only a voided attempt can be reopened |
Stream assignments
Controller CbtExaminationStreamController, prefix cbt/examinations/:examinationId/streams, user type staff.
| Method and path | operationId | Notes from the operation text |
|---|---|---|
POST / | assignCbtExaminationStream | 201 CbtExaminationStreamDto. Body AssignCbtExaminationStreamDto |
GET / | listCbtExaminationStreams | 200 |
PATCH /:assignmentId | updateCbtExaminationStream | Window and cap. streamId cannot change |
DELETE /:assignmentId | unassignCbtExaminationStream | 200 { "message": "Stream assignment removed successfully" }. Blocked when an enrolled student has a non-voided attempt |
Questions
Controller CbtQuestionController, prefix cbt/examinations/:examinationId/questions, user type staff.
| Method and path | operationId | Notes |
|---|---|---|
GET /context | getCbtQuestionContext | 200 CbtQuestionContextDto |
POST /generate | generateCbtQuestions | 202 { "message": "Generation queued" } |
POST /extract | extractCbtQuestions | 202 { "message": "Extraction queued" } |
POST /import-csv | importCbtQuestionsCsv | Multipart field file. MaxFileSizeValidator is 2 MiB. 201 ImportCbtQuestionsResultDto. The text says invalid rows are skipped |
POST / | addCbtQuestion | 201 CbtQuestionDto |
GET / | listCbtQuestions | 200 |
POST /reorder | reorderCbtQuestions | Body lists every question id |
PATCH /:questionId | updateCbtQuestion | 404 “Question not found.” |
DELETE /:questionId | deleteCbtQuestion | 200 { "message": "Question deleted successfully" } |
Sources
Naalya-API a5dff0c208d5193c274d3d1f87787b55344d5d30: the five controllers, cbt-access.service.ts, cbt-student-access.service.ts, cbt-grading.service.ts (voidAttempt, reopenAttempt, finalizeAttempt), and a fragment of loadManageableExam in cbt-examination.service.ts. Request DTO field lists other than the CSV size limit were not copied. No route was called.
CBT exams
The computer-based-testing domain, exam, questions, per-stream assignments, and attempts, with the exam window living on the stream join.
Authoring and access
Subject-scoped exam creation, the draft-publish-close lifecycle, per-stream assignment rules, and the relationship-based CbtAccessService.