aboutsummaryrefslogtreecommitdiff
path: root/item/hooks.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 20:31:56 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2023-09-03 20:31:56 +0530
commit076dcc7633fd0537c0255a98a31a59ca6f5d9de4 (patch)
treea18c772e7a2e96959368e39bebe04d9f50168f69 /item/hooks.go
parent520ed8f6387e0744a21a52912418e3acb08d18a5 (diff)
user can only access data generated by the same user now
Diffstat (limited to 'item/hooks.go')
-rw-r--r--item/hooks.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/item/hooks.go b/item/hooks.go
index 558a8cb..5a27114 100644
--- a/item/hooks.go
+++ b/item/hooks.go
@@ -25,7 +25,8 @@ import (
func (i *SavedItem) BeforeSave(tx *gorm.DB) error {
var err error
- err = checkIfBrandExists(i.BrandID, i.UserID)
+ // also checks if brand actually exists
+ err = checkBrandOwnership(i.BrandID, i.UserID)
if err != nil {
return err
}
@@ -53,5 +54,8 @@ func (b *Brand) BeforeDelete(tx *gorm.DB) error {
return errors.ErrNoWhereCondition
}
+ // delete all items
+ db.Where("brand_id = ? and user_id = ?", b.ID, b.UserID).Delete(&SavedItem{})
+
return nil
}