Files
Edu/services/core-edu/src/exams/exams.repository.ts
SpecialX 4533da6484 feat(core-edu): 修复服务启动并打通考试作业成绩端到端链路
database.ts 导出 db 常量替代 getDb()
env.ts JWT_SECRET 改 optional 并新增 DEV_MODE
kafka.ts connectKafka 加 try/catch 不阻塞启动
main.ts 去全局前缀 connectKafka 改非阻塞
app.module 移除未用模块加 HealthModule
controller 路由去前缀去 UseGuards 从 x-user-id 读身份
service datetime ISO 字符串转 Date 修复 drizzle 错误
修正相对 import 路径
health/lifecycle 改用 Drizzle 原生查询
新增 core-edu-init.sql 初始化 4 张表

端到端验证: exams/homework/grades 全部 201/200
Outbox 事件正确写入 core_edu_outbox 表
2026-07-09 08:02:22 +08:00

29 lines
798 B
TypeScript

import { eq } from "drizzle-orm";
import { db } from "../config/database.js";
import { exams, type Exam, type NewExam } from "./exams.schema.js";
export class ExamsRepository {
async findById(id: string): Promise<Exam | undefined> {
const [result] = await db
.select()
.from(exams)
.where(eq(exams.id, id))
.limit(1);
return result;
}
async findByClassId(classId: string): Promise<Exam[]> {
return db.select().from(exams).where(eq(exams.classId, classId));
}
async update(id: string, data: Partial<NewExam>): Promise<void> {
await db.update(exams).set(data).where(eq(exams.id, id));
}
async delete(id: string): Promise<void> {
await db.delete(exams).where(eq(exams.id, id));
}
}
export const examsRepository = new ExamsRepository();