(id: string)
| 78 | } |
| 79 | |
| 80 | export async function deleteLesson(id: string) { |
| 81 | const [deletedLesson, courseId] = await db.transaction(async trx => { |
| 82 | const [deletedLesson] = await trx |
| 83 | .delete(LessonTable) |
| 84 | .where(eq(LessonTable.id, id)) |
| 85 | .returning() |
| 86 | if (deletedLesson == null) { |
| 87 | trx.rollback() |
| 88 | throw new Error("Failed to delete lesson") |
| 89 | } |
| 90 | |
| 91 | const section = await trx.query.CourseSectionTable.findFirst({ |
| 92 | columns: { courseId: true }, |
| 93 | where: ({ id }, { eq }) => eq(id, deletedLesson.sectionId), |
| 94 | }) |
| 95 | |
| 96 | if (section == null) return trx.rollback() |
| 97 | |
| 98 | return [deletedLesson, section.courseId] |
| 99 | }) |
| 100 | |
| 101 | revalidateLessonCache({ |
| 102 | id: deletedLesson.id, |
| 103 | courseId, |
| 104 | }) |
| 105 | |
| 106 | return deletedLesson |
| 107 | } |
| 108 | |
| 109 | export async function updateLessonOrders(lessonIds: string[]) { |
| 110 | const [lessons, courseId] = await db.transaction(async trx => { |
nothing calls this directly
no test coverage detected