refactor: fix all P0/P1/P2 bugs and architecture issues
Bug fixes (from bugs/ directory): - Fix cross-module DB queries in 9 modules (homework, grades, parent, diagnostic, elective, proctoring, notifications, scheduling, classes) by routing through data-access functions - Fix shared/lib <-> auth circular dependency via new session.ts module - Fix divide-by-zero guard in grades data-access - Fix audit export data truncation (paginated fetch for full datasets) - Fix missing transactions in homework grading and elective lottery - Fix missing revalidatePath in course-plans actions - Fix frontend permission checks using requirePermission instead of requireAuth - Fix dashboard role routing using session.user.roles - Fix student auth pattern (migrate getDemoStudentUser to users module) - Fix ActionState return type handling in components Code quality fixes: - Remove 60+ as type assertions (replace with type guards) - Remove non-null assertions (use optional chaining or explicit checks) - Convert dynamic imports to static imports (grades, diagnostic) - Add React.cache() wrapping for read functions - Parallelize independent queries with Promise.all - Add explicit return types to 30+ arrow functions - Replace any with unknown + type guards - Fix import type for type-only imports - Add Zod validation schemas for classes and diagnostic modules - Extract duplicate code (normalizeRoleName, normalizeBcryptHash, logger IP extraction) - Add console.error to silent catch blocks - Fix permission naming consistency (exam:proctor_read -> exam:proctor:read) Architecture doc sync: - Update 004_architecture_impact_map.md and 005_architecture_data.json - Update management-modules-audit.md for P0-7 cross-module fix Moved deleted proctoring event route to deletes/ folder.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -49,28 +49,29 @@
|
||||
|
||||
---
|
||||
|
||||
### 2.2 classes 模块 — 🟡 需改进(文件拆分已修复,跨模块耦合仍存在)
|
||||
### 2.2 classes 模块 — 🟡 需改进(文件拆分已修复,跨模块耦合部分已修复)
|
||||
|
||||
**文件清单**:actions.ts (676 行) / data-access.ts (548 行) / data-access-stats.ts (531 行) / data-access-schedule.ts (194 行) / data-access-students.ts (244 行) / data-access-admin.ts (406 行) / types.ts (201 行)
|
||||
**文件清单**:actions.ts (676 行) / data-access.ts (548 行) / data-access-stats.ts (513 行) / data-access-schedule.ts (194 行) / data-access-students.ts (253 行) / data-access-admin.ts (406 行) / types.ts (201 行)
|
||||
|
||||
> ✅ `data-access.ts` 已于 2026-06-17 拆分为 5 个文件,所有文件均 ≤800 行,通过 re-export 保持向后兼容。
|
||||
> ✅ P0-7 已于 2026-06-18 修复:`data-access-stats.ts` 和 `data-access-students.ts` 不再直查 homework/exams 表,改为调用 `homework/data-access-classes.ts` 暴露的函数。
|
||||
|
||||
#### 2.2.1 职责混乱 — 混入三个外部业务领域(拆分后仍存在于子文件中)
|
||||
|
||||
`data-access-*.ts` 文件群仍承载了四个业务领域的逻辑(已按职责分文件,但跨域逻辑尚未迁移回所属模块):
|
||||
`data-access-*.ts` 文件群仍承载了四个业务领域的逻辑(已按职责分文件,homework 跨域查询已通过 data-access-classes 封装):
|
||||
|
||||
| 文件 | 逻辑 | 应属模块 |
|
||||
|------|------|---------|
|
||||
| data-access.ts | 教师身份解析、班级访问控制、班级 CRUD | classes(合理) |
|
||||
| data-access-students.ts | 班级学生查询 | classes(合理) |
|
||||
| data-access-stats.ts | `getClassHomeworkInsights` / `getGradeHomeworkInsights` 班级/年级作业洞察 | **homework** |
|
||||
| data-access-stats.ts | `getClassHomeworkInsights` / `getGradeHomeworkInsights` 班级/年级作业洞察 | classes(✅ P0-7 已修复:通过 `homework/data-access-classes` 获取数据) |
|
||||
| data-access-schedule.ts | 课表查询 `getClassSchedule`、课表项 CRUD | **scheduling** |
|
||||
| data-access-admin.ts | `getStudentsSubjectScores` 学生科目成绩 | **grades / homework** |
|
||||
| data-access-admin.ts | `getStudentsSubjectScores` 学生科目成绩 | classes(✅ P0-7 已修复:通过 `homework/data-access-classes` 获取数据) |
|
||||
|
||||
**关键问题**(P1-1 待修复):
|
||||
- `getClassHomeworkInsights` 和 `getGradeHomeworkInsights` 直接查询 `homeworkAssignments`、`homeworkSubmissions`、`homeworkAssignmentTargets`、`homeworkAssignmentQuestions`、`exams` 五张表,属于 homework 模块的核心业务,不应存在于 classes 模块。
|
||||
**关键问题**(P1-1 部分已修复):
|
||||
- ✅ P0-7 已修复:`getClassHomeworkInsights` 和 `getGradeHomeworkInsights` 不再直接查询 `homeworkAssignments`、`homeworkSubmissions`、`homeworkAssignmentTargets`、`homeworkAssignmentQuestions`、`exams` 表,改为调用 `homework/data-access-classes.ts` 暴露的函数(`getAssignmentIdsForStudents`/`getHomeworkAssignmentsWithSubject`/`getHomeworkAssignmentsByIds`/`getAssignmentMaxScoreById`/`getAssignmentTargetCounts`/`getHomeworkSubmissionsForStudents`)。
|
||||
- ✅ P0-7 已修复:`getStudentsSubjectScores` 不再直接关联 `homeworkSubmissions` + `exams` + `subjects`,改为调用 `homework/data-access-classes.ts` 暴露的函数(`getAssignmentIdsForStudents`/`getPublishedHomeworkAssignmentsWithSubject`/`getHomeworkSubmissionsForAssignments`)。
|
||||
- 课表 CRUD(`createClassScheduleItem` / `updateClassScheduleItem` / `deleteClassScheduleItem`)写入 `classSchedule` 表,P0-6 已统一 scheduling/data-access 为写入口,但 classes 侧的写函数仍存在(待后续迁移)。
|
||||
- `getStudentsSubjectScores` 直接关联 `homeworkSubmissions` + `exams` + `subjects` 计算学生科目分数,属于成绩分析逻辑。
|
||||
|
||||
#### 2.2.2 types.ts 跨领域类型污染
|
||||
|
||||
|
||||
Reference in New Issue
Block a user