fix: return updated lesson from UpdateSubModuleLesson after is_active false

GetSubModuleLessonByID filters is_active=true, so refetch failed with 500
after soft-deactivating. Use RETURNING row from the update instead.

Made-with: Cursor
This commit is contained in:
Yared Yemane 2026-04-18 02:54:47 -07:00
parent ce1b827768
commit 24f1aca97a

View File

@ -1956,7 +1956,7 @@ func (h *Handler) UpdateSubModuleLesson(c *fiber.Ctx) error {
targetIsActive = *req.IsActive
}
if _, err := h.analyticsDB.UpdateSubModuleLesson(c.Context(), dbgen.UpdateSubModuleLessonParams{
updatedLesson, err := h.analyticsDB.UpdateSubModuleLesson(c.Context(), dbgen.UpdateSubModuleLessonParams{
SubModuleID: targetSubModuleID,
Title: targetTitle,
Description: targetDescription,
@ -1968,17 +1968,10 @@ func (h *Handler) UpdateSubModuleLesson(c *fiber.Ctx) error {
DisplayOrder: targetDisplayOrder,
IsActive: targetIsActive,
ID: lessonID,
}); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
Message: "Failed to update lesson",
Error: err.Error(),
})
}
updatedLesson, err := h.analyticsDB.GetSubModuleLessonByID(c.Context(), lessonID)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(domain.ErrorResponse{
Message: "Lesson updated but failed to fetch latest detail",
Message: "Failed to update lesson",
Error: err.Error(),
})
}
@ -2989,4 +2982,3 @@ func (h *Handler) DeleteModuleCapstone(c *fiber.Ctx) error {
}
return c.JSON(domain.Response{Message: "Module capstone deleted"})
}