Files
Learn_System/backend
Maxim Dolgolyov 90c8464356 feat(gamification): Phase 2 — taxonomy + grouped UI for achievements
Achievements gain four new columns: group_slug, track, tier, sort_order.
Existing 36 are backfilled into 5 groups (onboarding/volume/mastery/
consistency/exploration) by migration 030; 'social' stays empty until
Phase 3 adds class/leaderboard/live-quiz tracks.

Tracks bundle escalating thresholds into one progression (tests_10/50/
100 → track='tests', tiers 1-3), so the UI can show '★★★' on the top
tier and the user understands the relationship. sort_order is reserved
in blocks of 10 inside groups of 100, leaving room for inserts without
renumbering.

Backend:
  • migration 030 adds the columns + index + backfill UPDATEs
  • _shared.ACHIEVEMENT_DEFS gains group/track/tier/sort_order per row
  • _shared exports new ACHIEVEMENT_GROUPS metadata for the UI
  • service.seedAchievements writes the new fields on insert AND
    backfills them via UPDATE on existing rows (fresh installs +
    pre-migration installs both end up consistent)
  • _shared.stmts.getAllAchs SELECT updated, ORDER BY sort_order
  • gamification/api.getAchievements forwards the new fields

Frontend:
  • profile.html groups achievements by group_slug with a per-section
    header (icon + title + 'unlocked / total' chip) and a tier-star
    badge (★★ etc.) on tier ≥ 2 items
  • Hard-coded ACH_GROUPS mirror of the backend list (small, stable)
  • New CSS for .ach-group / .ach-group-head / .ach-tier

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 20:19:46 +03:00
..

LearnSpace Backend — Фаза 1

Быстрый старт

cd backend
npm install

# 1. Скопировать и заполнить переменные окружения
cp .env.example .env

# 2. Создать базу данных в PostgreSQL
createdb learnspace

# 3. Применить миграции (создать таблицы)
npm run migrate

# 4. Загрузить тестовые вопросы
npm run seed

# 5. Запустить сервер
npm run dev

API

Auth

Метод URL Тело Описание
POST /api/auth/register { email, password, name } Регистрация
POST /api/auth/login { email, password } Вход
GET /api/auth/me Текущий пользователь

Предметы

Метод URL Описание
GET /api/subjects Список предметов
GET /api/subjects/:slug/topics Темы предмета

Сессии тестирования

Метод URL Тело Описание
POST /api/sessions { subject_slug, mode, count, topic_id? } Начать тест
POST /api/sessions/:id/answer { question_id, option_id, time_spent_sec? } Отправить ответ
POST /api/sessions/:id/finish Завершить тест + разбор
GET /api/sessions/:id/result Результат завершённого теста
GET /api/sessions/history История тестов

Все /api/sessions/* требуют заголовок:

Authorization: Bearer <token>

Добавление вопросов

Создать JSON-файл в data/ по образцу questions-bio.json:

{
  "subject": "chem",
  "topics": [{ "name": "Органическая химия", "order": 1 }],
  "questions": [
    {
      "topic": "Органическая химия",
      "difficulty": 2,
      "text": "Текст вопроса",
      "options": ["А", "Б", "В", "Г"],
      "answer": 0,
      "explanation": "Объяснение правильного ответа"
    }
  ]
}

Затем повторно запустить npm run seed.

Структура проекта

backend/
├── data/                     ← JSON с вопросами
├── src/
│   ├── server.js             ← точка входа
│   ├── middleware/auth.js    ← JWT верификация
│   ├── db/
│   │   ├── pool.js           ← соединение с PostgreSQL
│   │   ├── migrate.js        ← запуск миграций
│   │   ├── seed.js           ← загрузка вопросов
│   │   └── migrations/       ← SQL-файлы схемы
│   ├── routes/               ← маршруты
│   └── controllers/          ← бизнес-логика
└── .env.example