34 个服务端文件替换 86 处 console.* 调用为 createModuleLogger。模块覆盖: exams/audit/school/files/classes/notifications/grades/auth/homework/announcements/settings/lesson-preparation。shared lib: cache/redis-store, rate-limit/redis-limiter, redis-client, exam-homework-port。API routes: web-vitals, cron/audit-cleanup, proctoring/event。 web-vitals/route.ts 从 edge runtime 改为 nodejs runtime,因 pino 依赖 Node.js stream 内置模块,不兼容 Edge Runtime (V8 Isolate)。
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import "server-only"
|
||
|
||
import { getQuestions } from "@/modules/questions/data-access"
|
||
import type { QuestionPickerItem, QuestionPickerParams } from "../providers/lesson-plan-provider"
|
||
import { createModuleLogger } from "@/shared/lib/logger"
|
||
|
||
const log = createModuleLogger("lesson-preparation")
|
||
|
||
/**
|
||
* 跨模块题目查询桥接器(V4 P0-4 修复)。
|
||
*
|
||
* 历史上 `services/default-data-service.ts` 直接 `import { getQuestionsAction } from "@/modules/questions/actions"`,
|
||
* 违反"模块内部组件绝不直接 import 其他业务模块的 actions"原则。
|
||
*
|
||
* 本桥接器:
|
||
* 1. 改为 `data-access → data-access` 通信(项目规则允许)
|
||
* 2. 仅做"参数/返回值适配"——把 questions 模块的形状转换为备课模块 picker 期望的形状
|
||
* 3. 保留为独立文件,便于未来按"完全解耦"目标替换为 Context 注入的 QuestionService 实现
|
||
*
|
||
* 中长期目标(审计报告 M-category):通过 LessonPlanProvider 在 app 层注入 QuestionService,
|
||
* 备课模块不再有任何对 questions 模块的 import。
|
||
*/
|
||
export async function fetchExternalQuestions(
|
||
params: QuestionPickerParams,
|
||
): Promise<{ success: boolean; data?: { data: QuestionPickerItem[] }; message?: string }> {
|
||
try {
|
||
const res = await getQuestions({
|
||
q: params.q,
|
||
type: params.type,
|
||
difficulty: params.difficulty,
|
||
page: 1,
|
||
pageSize: 50,
|
||
})
|
||
|
||
const items: QuestionPickerItem[] = res.data.map((q) => ({
|
||
id: q.id,
|
||
type: q.type,
|
||
difficulty: q.difficulty,
|
||
content: q.content,
|
||
}))
|
||
|
||
return { success: true, data: { data: items } }
|
||
} catch (e) {
|
||
log.error({ err: e }, "fetchExternalQuestions failed")
|
||
return { success: false, message: "external_questions_unavailable" }
|
||
}
|
||
}
|