51
apps/web/src/lib/repositories/teacher.repository.ts
Executable file
51
apps/web/src/lib/repositories/teacher.repository.ts
Executable file
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user