(data: typeof LessonTable.$inferInsert)
| 14 | } |
| 15 | |
| 16 | export 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 | |
| 37 | export async function updateLesson( |
| 38 | id: string, |
no test coverage detected