feat: 新增备课模块并修复全模块 P0/P1/P2 缺陷
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
主要变更: - 新增 lesson-preparation 模块: 备课编辑器、节点编辑、AI 建议、知识点选择、版本历史、作业发布 - 新增 shared 通用组件: charts/question-bank-filters/schedule-list/ui (chip-nav/filter-bar/page-header/stat-card/stat-item) - 新增 student/admin 端 loading.tsx 与 error.tsx, 优化加载与错误态体验 - 新增 teacher/lesson-plans 页面 (列表/新建/编辑) - 新增 drizzle 迁移 0002_tiny_lionheart 及 snapshot - 新增 textbooks/schema.ts 与 exams/utils/normalize-structure.ts - 修复 Tiptap v3 SSR hydration 崩溃 (rich-text-block immediatelyRender: false) - 重构多模块 data-access/actions/组件, 修复权限校验与类型规范 - 同步架构文档 004/005 反映新增模块、导出、依赖关系 - 归档 bugs/* 测试报告与 e2e 测试脚本 (admin/parent/student/teacher web_test)
This commit is contained in:
@@ -50,14 +50,14 @@ export const getSessionTeacherId = async (): Promise<string | null> => {
|
||||
|
||||
// Strict subjectId-based mapping: no aliasing
|
||||
|
||||
export const isDuplicateInvitationCodeError = (err: unknown) => {
|
||||
export const isDuplicateInvitationCodeError = (err: unknown): boolean => {
|
||||
if (!err) return false
|
||||
const msg = err instanceof Error ? err.message : String(err)
|
||||
const m = msg.toLowerCase()
|
||||
return m.includes("duplicate") && (m.includes("invitation") || m.includes("invitation_code"))
|
||||
}
|
||||
|
||||
const generateInvitationCode = () => {
|
||||
const generateInvitationCode = (): string => {
|
||||
const n = randomInt(0, 1_000_000)
|
||||
return String(n).padStart(6, "0")
|
||||
}
|
||||
@@ -90,14 +90,15 @@ export const getClassSubjects = async (): Promise<string[]> => {
|
||||
return Array.from(new Set(names))
|
||||
}
|
||||
|
||||
const normalizeSortText = (v: string | null | undefined) => (typeof v === "string" ? v.trim().toLowerCase() : "")
|
||||
const normalizeSortText = (v: string | null | undefined): string =>
|
||||
typeof v === "string" ? v.trim().toLowerCase() : ""
|
||||
|
||||
const parseFirstInt = (v: string) => {
|
||||
const parseFirstInt = (v: string): number | null => {
|
||||
const m = v.match(/\d+/)
|
||||
return m ? Number(m[0]) : null
|
||||
}
|
||||
|
||||
const compareGradeLabel = (a: string, b: string) => {
|
||||
const compareGradeLabel = (a: string, b: string): number => {
|
||||
const aNum = parseFirstInt(a)
|
||||
const bNum = parseFirstInt(b)
|
||||
if (typeof aNum === "number" && typeof bNum === "number" && aNum !== bNum) return aNum - bNum
|
||||
@@ -107,7 +108,7 @@ const compareGradeLabel = (a: string, b: string) => {
|
||||
export const compareClassLike = (
|
||||
a: { schoolName?: string | null; grade: string; name: string; homeroom?: string | null; room?: string | null },
|
||||
b: { schoolName?: string | null; grade: string; name: string; homeroom?: string | null; room?: string | null }
|
||||
) => {
|
||||
): number => {
|
||||
const schoolCmp = normalizeSortText(a.schoolName).localeCompare(normalizeSortText(b.schoolName))
|
||||
if (schoolCmp !== 0) return schoolCmp
|
||||
|
||||
@@ -228,6 +229,32 @@ export const getTeacherSubjectIdsByClass = async (classId: string, teacherId: st
|
||||
return getTeacherSubjectIdsForClass(teacherId, classId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个班级的所有教师 ID(班主任 + 任课教师)。
|
||||
* 供跨模块调用使用,避免直接查询 classes / classSubjectTeachers 表。
|
||||
*/
|
||||
export const getTeacherIdsByClassIds = async (classIds: string[]): Promise<string[]> => {
|
||||
if (classIds.length === 0) return []
|
||||
const [homeroomRows, subjectRows] = await Promise.all([
|
||||
db
|
||||
.select({ teacherId: classes.teacherId })
|
||||
.from(classes)
|
||||
.where(inArray(classes.id, classIds)),
|
||||
db
|
||||
.select({ teacherId: classSubjectTeachers.teacherId })
|
||||
.from(classSubjectTeachers)
|
||||
.where(inArray(classSubjectTeachers.classId, classIds)),
|
||||
])
|
||||
const set = new Set<string>()
|
||||
for (const r of homeroomRows) {
|
||||
if (r.teacherId) set.add(r.teacherId)
|
||||
}
|
||||
for (const r of subjectRows) {
|
||||
if (r.teacherId) set.add(r.teacherId)
|
||||
}
|
||||
return Array.from(set)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取学生当前活跃班级的 ID。
|
||||
* 供跨模块调用使用,避免直接查询 classEnrollments 表。
|
||||
@@ -242,6 +269,23 @@ export const getStudentActiveClassId = async (studentId: string): Promise<string
|
||||
return row?.classId ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取学生当前活跃班级的 ID 与名称(一次 JOIN 查询)。
|
||||
* 供跨模块调用使用,避免分别查询 classEnrollments 与 classes 表。
|
||||
*/
|
||||
export const getStudentActiveClass = async (
|
||||
studentId: string,
|
||||
): Promise<{ classId: string; className: string } | null> => {
|
||||
const [row] = await db
|
||||
.select({ classId: classes.id, className: classes.name })
|
||||
.from(classEnrollments)
|
||||
.innerJoin(classes, eq(classes.id, classEnrollments.classId))
|
||||
.where(and(eq(classEnrollments.studentId, studentId), eq(classEnrollments.status, "active")))
|
||||
.orderBy(asc(classEnrollments.createdAt))
|
||||
.limit(1)
|
||||
return row ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取学生当前活跃班级对应的年级 ID。
|
||||
* 供跨模块调用使用,避免直接查询 classEnrollments/classes 表。
|
||||
@@ -368,7 +412,8 @@ export const getTeacherClasses = cache(async (params?: { teacherId?: string }):
|
||||
.where(inArray(classes.id, allIds))
|
||||
.groupBy(classes.id, classes.schoolName, classes.name, classes.grade, classes.homeroom, classes.room, classes.invitationCode)
|
||||
.orderBy(asc(classes.schoolName), asc(classes.grade), asc(classes.name), asc(classes.homeroom), asc(classes.room))
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error("getTeacherClasses query failed:", error)
|
||||
return []
|
||||
}
|
||||
})()
|
||||
@@ -672,7 +717,9 @@ export async function enrollTeacherByInvitationCode(
|
||||
|
||||
const preferred = DEFAULT_CLASS_SUBJECTS.find((s) => subjectRows.some((r) => r.name === s))
|
||||
if (!preferred) throw new Error("Class already has assigned teachers")
|
||||
const sid = subjectRows.find((r) => r.name === preferred)!.id
|
||||
const subjectRow = subjectRows.find((r) => r.name === preferred)
|
||||
if (!subjectRow) throw new Error("Subject not found")
|
||||
const sid = subjectRow.id
|
||||
|
||||
await db
|
||||
.update(classSubjectTeachers)
|
||||
|
||||
Reference in New Issue
Block a user