Files
Edu/services/content/src/questions/questions.dto.ts
SpecialX 99580fa13a feat(content): docker 本地测试通过 + P5 ES 集成 + P6+ 审核工作流/可视化/可观测性
P5 ES 集成:
- config/elasticsearch.ts: 惰性初始化 + ik_max_word→standard 回退
- shared/sync/es-sync.worker.ts: Kafka 消费 question 事件并索引 ES
- questions search API: ES 优先, MySQL LIKE 降级
- ensureQuestionIndex() 幂等创建, IK 不可用回退 standard
- main.ts: 启动 ensureQuestionIndex + esSyncWorker 生命周期管理

P6+ 审核工作流/可视化/可观测性:
- Question 状态机: draft→pending_review→published→archived
- 非法转换拦截
- 知识图谱可视化 API: Neo4j 优先 + MySQL 降级
- Cypher 返回标量避免 Node 包装对象问题
- 教材版本管理: GET /textbooks/versions + archive
- 5 个 Prometheus 指标 + /readyz Outbox 积压检查

Docker 本地测试 (8 类全通过):
- healthz/readyz (5 依赖 ok)
- REST CRUD (textbook/chapter/kp/question)
- ES 全文检索命中
- 审核工作流状态机 (合法/非法转换)
- Outbox 事件驱动 (8 事件全 published)
- Neo4j 同步 (KnowledgePoint 节点创建)
- 可视化 (nodes/edges 正确)
- Prometheus 指标

docs/nextstep.md: 上游 (MySQL/Neo4j/Kafka/Redis/ES/ai)
+ 下游 (teacher-bff/student-bff/parent-bff/data-ana/api-gateway/ai)
2026-07-14 00:58:50 +08:00

68 lines
2.2 KiB
TypeScript

import { z } from "zod";
export const questionTypeSchema = z.enum([
"single_choice",
"multiple_choice",
"short_answer",
"essay",
]);
export const questionSourceSchema = z.enum([
"manual",
"ai_generated",
"imported",
]);
export const createQuestionSchema = z.object({
knowledgePointId: z.string().min(1).max(32),
type: questionTypeSchema,
content: z.string().min(1),
options: z.record(z.unknown()).nullish(),
answer: z.string().min(1),
explanation: z.string().optional(),
difficulty: z.number().int().min(1).max(5).optional().default(3),
source: questionSourceSchema.optional().default("manual"),
createdBy: z.string().min(1).max(32),
metadata: z.record(z.unknown()).nullish(),
});
export const updateQuestionSchema = z.object({
content: z.string().min(1).optional(),
options: z.record(z.unknown()).nullish(),
answer: z.string().min(1).optional(),
explanation: z.string().optional(),
difficulty: z.number().int().min(1).max(5).optional(),
status: z
.enum(["draft", "pending_review", "published", "rejected", "archived"])
.optional(),
});
export const listQuestionsSchema = z.object({
knowledgePointId: z.string().optional(),
type: questionTypeSchema.optional(),
difficulty: z.coerce.number().int().min(1).max(5).optional(),
status: z.string().optional(),
page: z.coerce.number().int().min(1).default(1),
pageSize: z.coerce.number().int().min(1).max(100).default(20),
});
export const searchQuestionsSchema = z.object({
q: z.string().optional(),
type: questionTypeSchema.optional(),
difficulty: z.coerce.number().int().min(1).max(5).optional(),
knowledgePointId: z.string().optional(),
page: z.coerce.number().int().min(1).default(1),
pageSize: z.coerce.number().int().min(1).max(100).default(20),
});
// P6.1: 审核拒绝原因 schema
export const rejectQuestionSchema = z.object({
reason: z.string().min(1).max(1000),
});
export type CreateQuestionDto = z.infer<typeof createQuestionSchema>;
export type UpdateQuestionDto = z.infer<typeof updateQuestionSchema>;
export type ListQuestionsDto = z.infer<typeof listQuestionsSchema>;
export type SearchQuestionsDto = z.infer<typeof searchQuestionsSchema>;
export type RejectQuestionDto = z.infer<typeof rejectQuestionSchema>;