feat(biochem): Фаза 5.5 — ачивки bc_* привязаны к событиям

gamification/service.js (checkPhase3Achievements): новый био-блок —
bc_first_molecule (есть сохранённая молекула), bc_5_challenges (>=5 решённых),
bc_20_challenges (>=20) из таблиц bio_user_molecules / bio_user_challenges.

biochemController.js: после решения задачи и сохранения молекулы вызывается
checkAchievements(req.user.id) — раньше начислялся только XP, ачивки не
триггерились. Слоты bc_* существовали в _shared.js, но были мёртвыми.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-05-30 15:41:38 +03:00
parent 84feca94d7
commit c1d532aaad
2 changed files with 22 additions and 1 deletions
@@ -343,6 +343,19 @@ function checkPhase3Achievements(userId, userRow) {
if (tb) unlockAchievement(userId, 'tb_first_para');
} catch (e) { /* table missing */ }
// ── biochem: решённые задачи + первая собранная молекула ───────
try {
const bc = db.prepare(`
SELECT COUNT(*) AS n FROM bio_user_challenges WHERE user_id = ?
`).get(userId)?.n || 0;
if (bc >= 5) unlockAchievement(userId, 'bc_5_challenges');
if (bc >= 20) unlockAchievement(userId, 'bc_20_challenges');
const mol = db.prepare(`
SELECT 1 FROM bio_user_molecules WHERE user_id = ? LIMIT 1
`).get(userId);
if (mol) unlockAchievement(userId, 'bc_first_molecule');
} catch (e) { /* bio tables missing on legacy install */ }
// ── flashcards: total reviews ──────────────────────────────────
try {
const fc = db.prepare(`