b1e645157a
По образцу classroom-split:
backend/src/controllers/gamificationController.js 859L → 31L (фасад)
backend/src/controllers/gamification/
_shared.js 194L — db, helpers (xpToLevel/levelMinXp/levelMaxXp/
rankName/RANKS), GOAL_TIERS, ACHIEVEMENT_DEFS,
AVATAR_FRAMES, stmts (все prepared statements)
service.js 393L — бизнес-логика: awardXP/awardCoins/getXPInfo/
updateStreak, seedAchievements/
unlockAchievement/pushAchievementNotif/
checkAchievements/checkRedBookAchievements,
hooks (onLessonComplete/onTestFinished/
onClassJoined/onLabExperiment),
daily (getDailyGoal/updateDailyGoal),
challenges (_currentWeek/ensureChallenges/
updateChallenges)
api.js 152L — HTTP handlers /api/gamification/*: getMe,
getFrames, setFrame, setGoalTier,
getAchievements, getLeaderboard, getXPHistory,
getChallenges, claimChallenge
admin.js 70L — /api/gamification/admin/*: adminAward,
adminReset, adminGamStats, adminGetUser
Фасад gamificationController.js перереэкспортирует ВСЕ 24 функции,
которые были в оригинале. Никаких изменений в:
- routes/* (импорты не менялись)
- biochemController, classController, gamesController,
lessonController, petController, redBookController,
sessionController, db/seed-permissions, db/legacy-migrate
(все 10+ внешних импортов 'gamificationController' работают)
Проверено: node --check OK, server restart, /api/gamification/*
возвращает 401 (auth req'd) — маршруты живые. Объект module.exports
содержит все 24 функции (тест: Object.keys чтения фасада).
Самый большой контроллер в проекте теперь хорошо структурирован:
любой разработчик мгновенно находит нужный кусок.
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
'use strict';
|
|
/**
|
|
* Gamification — facade module.
|
|
* Implementation split into ./gamification/* domain files.
|
|
* Public surface (re-exports) is identical to the pre-split single file
|
|
* for backwards compatibility with existing route mounts and inter-controller
|
|
* imports (biochem, classes, games, lessons, pet, redBook, session, etc.).
|
|
*/
|
|
|
|
const service = require('./gamification/service');
|
|
const api = require('./gamification/api');
|
|
const admin = require('./gamification/admin');
|
|
|
|
module.exports = {
|
|
// API handlers (mounted by routes/gamification.js)
|
|
...api,
|
|
// Admin handlers
|
|
...admin,
|
|
// Service functions for other controllers
|
|
awardXP: service.awardXP,
|
|
awardCoins: service.awardCoins,
|
|
seedAchievements: service.seedAchievements,
|
|
checkAchievements: service.checkAchievements,
|
|
checkRedBookAchievements: service.checkRedBookAchievements,
|
|
onTestFinished: service.onTestFinished,
|
|
onClassJoined: service.onClassJoined,
|
|
onLabExperiment: service.onLabExperiment,
|
|
onLessonComplete: service.onLessonComplete,
|
|
updateDailyGoal: service.updateDailyGoal,
|
|
updateChallenges: service.updateChallenges,
|
|
};
|