From 776522d8741752832981b17ec81deb11a298ef57 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 3 Sep 2023 16:18:20 +0530 Subject: different customers for different users --- customer/validators.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'customer/validators.go') diff --git a/customer/validators.go b/customer/validators.go index 6c51ad9..bfd244f 100644 --- a/customer/validators.go +++ b/customer/validators.go @@ -26,11 +26,11 @@ import ( // NOTE: very inefficient and really really really dumb but it works // TODO: find a better (or even a remotely good) way -func validateContactField(field, value string) error { +func validateContactField(field, value string, userId uint) error { if value != "" { var count int64 err := db.Model(&CustomerContact{}). - Where(field + " = ?", value). + Where(field + " = ? and user_id = ?", value, userId). Count(&count). Error @@ -64,7 +64,7 @@ func (c *CustomerContact) validate() error { var err error for _, i := range [][]string{{"phone", c.Phone}, {"email", c.Email}, {"website", c.Website}} { - err = validateContactField(i[0], i[1]) + err = validateContactField(i[0], i[1], c.UserID) if err != nil { return err } @@ -90,7 +90,7 @@ func (c *Customer) validate() error { var count int64 err := db.Model(&Customer{}). Select("gstin"). - Where("gstin = ?", c.Gstin). + Where("gstin = ? and user_id = ?", c.Gstin, c.UserID). Count(&count). Error -- cgit v1.2.3