Files
adventure/apps/web/src/lib/repositories/teacher.repository.ts
Zaine 3b37368e7d
Some checks failed
CI / test (push) Has been cancelled
initial 2
2026-06-26 09:26:50 +01:00

52 lines
1.2 KiB
TypeScript
Executable File

import { eq, desc } from "drizzle-orm";
import { db, teacherContent } from "@/lib/db";
export async function listTeacherContent(userId: string) {
return db
.select()
.from(teacherContent)
.where(eq(teacherContent.userId, userId))
.orderBy(desc(teacherContent.createdAt));
}
export async function findTeacherContentById(id: string) {
const [row] = await db.select().from(teacherContent).where(eq(teacherContent.id, id));
return row ?? null;
}
export async function insertTeacherContent(data: {
userId: string;
topic: string;
content: Record<string, unknown>;
explorationId?: string;
status?: string;
}) {
const [row] = await db
.insert(teacherContent)
.values({
userId: data.userId,
explorationId: data.explorationId,
topic: data.topic,
content: data.content,
status: data.status ?? "active",
})
.returning();
return row;
}
export async function updateTeacherContent(
id: string,
data: Partial<{
status: string;
completedNote: string;
completedAt: Date;
}>
) {
const [row] = await db
.update(teacherContent)
.set(data)
.where(eq(teacherContent.id, id))
.returning();
return row;
}