Fix for category when searching parents when ParentID is zero

This commit is contained in:
qowevisa 2024-08-03 10:52:38 +03:00
parent 12fd07c0a3
commit 5ce7223b92

View File

@ -22,12 +22,14 @@ var (
) )
func (c *Category) BeforeSave(tx *gorm.DB) error { func (c *Category) BeforeSave(tx *gorm.DB) error {
var parent Category if c.ParentID != 0 {
if err := tx.Find(&parent, Category{ParentID: c.ParentID, UserID: c.UserID}).Error; err != nil { var parent Category
return err if err := tx.Find(&parent, Category{ParentID: c.ParentID, UserID: c.UserID}).Error; err != nil {
} return err
if parent.ID == 0 { }
return ERROR_CATEGORY_PARENT_NOT_FOUND if parent.ID == 0 {
return ERROR_CATEGORY_PARENT_NOT_FOUND
}
} }
var dup Category var dup Category
if err := tx.Find(&dup, Category{Name: c.Name, UserID: c.UserID}).Error; err != nil { if err := tx.Find(&dup, Category{Name: c.Name, UserID: c.UserID}).Error; err != nil {