add restrict delete master data kandang group

This commit is contained in:
giovanni
2026-03-27 12:11:17 +07:00
parent 6510bccc76
commit 63cf0c6fac
2 changed files with 29 additions and 0 deletions
@@ -226,6 +226,16 @@ func (s kandangGroupService) DeleteOne(c *fiber.Ctx, id uint) error {
if err != nil {
return err
}
hasDailyChecklistRelation, err := s.Repository.HasDailyChecklistRelation(c.Context(), id)
if err != nil {
s.Log.Errorf("Failed to check daily checklist relation for kandang group %d: %+v", id, err)
return fiber.NewError(fiber.StatusInternalServerError, "Failed to check kandang group relation")
}
if hasDailyChecklistRelation {
return fiber.NewError(fiber.StatusConflict, "Kandang group tidak boleh dihapus karena masih memiliki relasi daily checklist")
}
if len(kandangGroup.Kandangs) > 0 {
return fiber.NewError(fiber.StatusConflict, "Kandang group tidak boleh dihapus karena masih memiliki relasi kandang")
}