aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/user/validators.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-11 20:55:48 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-10-11 20:55:48 +0530
commitbc154857fb5569d7c1fa9785cc891cb927a6a156 (patch)
tree590c9f6a00a1b97b2ee45cfa5a767558089affe0 /user/validators.go
parent8a47978ca17d2f251d67d12b0e34fa26bb1e4ace (diff)
removed per-user itemsv0.17.0
Diffstat (limited to 'user/validators.go')
-rw-r--r--user/validators.go45
1 files changed, 0 insertions, 45 deletions
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
}