MCPcopy Create free account
hub / github.com/WebDevSimplified/course-platform / insertLesson

Function insertLesson

src/features/lessons/db/lessons.ts:16–35  ·  view source on GitHub ↗
(data: typeof LessonTable.$inferInsert)

Source from the content-addressed store, hash-verified

14}
15
16export async function insertLesson(data: typeof LessonTable.$inferInsert) {
17 const [newLesson, courseId] = await db.transaction(async trx => {
18 const [[newLesson], section] = await Promise.all([
19 trx.insert(LessonTable).values(data).returning(),
20 trx.query.CourseSectionTable.findFirst({
21 columns: { courseId: true },
22 where: eq(CourseSectionTable.id, data.sectionId),
23 }),
24 ])
25
26 if (section == null) return trx.rollback()
27
28 return [newLesson, section.courseId]
29 })
30 if (newLesson == null) throw new Error("Failed to create lesson")
31
32 revalidateLessonCache({ courseId, id: newLesson.id })
33
34 return newLesson
35}
36
37export async function updateLesson(
38 id: string,

Callers 1

createLessonFunction · 0.90

Calls 1

revalidateLessonCacheFunction · 0.90

Tested by

no test coverage detected