Fix test correction: remove transaction, add error handling
Replaced db.transaction() wrapper (unreliable in node:sqlite at this version) with a plain loop. Added try/catch in the JS save handler so any server error surfaces as a visible toast instead of failing silently. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
0744ba9e39
commit
4ad11ea4ee
2 files changed
+14
-12
No files matched your search
@@ -539,11 +539,9 @@ app.patch('/api/tests/:testId/correct', requirePin, (req, res) => {
|
||||
if (!test) return res.status(404).json({ error: 'Test not found' });
|
||||
|
||||
const upd = db.prepare(`UPDATE test_answers SET correct = ? WHERE test_id = ? AND word_id = ?`);
|
||||
db.transaction(() => {
|
||||
for (const c of corrections) {
|
||||
upd.run(c.correct ? 1 : 0, testId, c.wordId);
|
||||
}
|
||||
})();
|
||||
for (const c of corrections) {
|
||||
upd.run(c.correct ? 1 : 0, testId, c.wordId);
|
||||
}
|
||||
|
||||
const newScore = db.prepare(`SELECT COUNT(*) AS n FROM test_answers WHERE test_id = ? AND correct = 1`).get(testId).n;
|
||||
db.prepare(`UPDATE tests SET score = ? WHERE id = ?`).run(newScore, testId);
|
||||
|
||||
Reference in new issue
Block a user