feat: add notes functionality to exam state and update UI for note-taking

This commit is contained in:
LaurensBartelds committed 2026-04-22 22:48:24 +02:00
1 parent d0b1ac0145
commit c4c1e1a45a
5 files changed
+90 -31

No files matched your search

+13 -2
View File
@@ -67,7 +67,7 @@ router.get('/:id', requireAuth, (req, res) => {
// ─── Save Result ─────────────────────────────────────────
router.post('/', requireAuth, (req, res) => {
try {
const { title, scorePoints, totalPoints, correctCount, gradedCount, passingScore, elapsedMs, state, exam, examId } = req.body
const { title, scorePoints, totalPoints, correctCount, gradedCount, passingScore, elapsedMs, notes, state, exam, examId } = req.body
if (
!title || scorePoints == null || totalPoints == null ||
@@ -77,6 +77,17 @@ router.post('/', requireAuth, (req, res) => {
return
}
let noteSource = ''
if (typeof notes === 'string') {
noteSource = notes
} else if (typeof state.notes === 'string') {
noteSource = state.notes
}
const normalizedState = {
...state,
notes: noteSource.slice(0, 1000),
}
const db = getDb()
const result = db.prepare(`
INSERT INTO exam_results (user_id, exam_id, title, score_points, total_points, correct_count, graded_count, passing_score, elapsed_ms, state_json, exam_json)
@@ -91,7 +102,7 @@ router.post('/', requireAuth, (req, res) => {
gradedCount,
passingScore ?? 60,
elapsedMs ?? 0,
JSON.stringify(state),
JSON.stringify(normalizedState),
JSON.stringify(exam),
)