From bc154857fb5569d7c1fa9785cc891cb927a6a156 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 11 Oct 2025 20:55:48 +0530 Subject: removed per-user items --- user/validators.go | 45 --------------------------------------------- 1 file changed, 45 deletions(-) (limited to 'user/validators.go') diff --git a/user/validators.go b/user/validators.go index b54457f..e497122 100644 --- a/user/validators.go +++ b/user/validators.go @@ -19,7 +19,6 @@ package user import ( "strings" - e "errors" "github.com/spf13/viper" "vidhukant.com/openbills/errors" "vidhukant.com/openbills/util" @@ -59,41 +58,6 @@ func validateUsername(username string) error { return nil } -// NOTE: very inefficient and really really really dumb but it works -// TODO: find a better (or even a remotely good) way -func validateUserField(field, value string) error { - if value != "" { - var count int64 - err := db.Model(&User{}). - Where(field + " = ?", value). - Count(&count). - Error - - if err != nil { - return err - } - - if count > 0 { - switch(field) { - case "username": - return errors.ErrNonUniqueUsername - case "phone": - return errors.ErrNonUniquePhone - case "email": - return errors.ErrNonUniqueEmail - case "website": - return errors.ErrNonUniqueWebsite - case "gstin": - return errors.ErrNonUniqueGSTIN - default: - return e.New(field + " is not unique") - } - } - } - - return nil -} - func (u *User) validate() error { u.Username = strings.TrimSpace(u.Username) u.Email = strings.TrimSpace(u.Email) @@ -102,8 +66,6 @@ func (u *User) validate() error { u.Gstin = strings.TrimSpace(u.Gstin) u.IsVerified = false - // TODO: validate username length and stuff - // don't validate if GSTIN is empty if u.Gstin != "" && !util.ValidateGstin(u.Gstin) { return errors.ErrInvalidGSTIN @@ -146,12 +108,5 @@ func (u *User) validate() error { return err } - for _, i := range [][]string{{"username", u.Username}, {"email", u.Email}, {"website", u.Website}, {"gstin", u.Gstin}, {"phone", u.Phone}} { - err := validateUserField(i[0], i[1]) - if err != nil { - return err - } - } - return nil } -- cgit v1.2.3