From 12d24a5aed888dd0e710957ae07e71745c17315a Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Mon, 1 Feb 2021 10:49:57 -0800 Subject: [PATCH] Check user not found for updateUser --- server/services/store/sqlstore/user.go | 52 +++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/server/services/store/sqlstore/user.go b/server/services/store/sqlstore/user.go index 6f43786f2..2e049ed7d 100644 --- a/server/services/store/sqlstore/user.go +++ b/server/services/store/sqlstore/user.go @@ -2,6 +2,7 @@ package sqlstore import ( "encoding/json" + "errors" "time" "github.com/mattermost/focalboard/server/model" @@ -91,8 +92,21 @@ func (s *SQLStore) UpdateUser(user *model.User) error { Set("update_at", now). Where(sq.Eq{"id": user.ID}) - _, err = query.Exec() - return err + result, err := query.Exec() + if err != nil { + return err + } + + rowCount, err := result.RowsAffected() + if err != nil { + return err + } + + if rowCount < 1 { + return errors.New("user not found") + } + + return nil } func (s *SQLStore) UpdateUserPassword(username string, password string) error { @@ -103,8 +117,21 @@ func (s *SQLStore) UpdateUserPassword(username string, password string) error { Set("update_at", now). Where(sq.Eq{"username": username}) - _, err := query.Exec() - return err + result, err := query.Exec() + if err != nil { + return err + } + + rowCount, err := result.RowsAffected() + if err != nil { + return err + } + + if rowCount < 1 { + return errors.New("user not found") + } + + return nil } func (s *SQLStore) UpdateUserPasswordByID(userID string, password string) error { @@ -115,6 +142,19 @@ func (s *SQLStore) UpdateUserPasswordByID(userID string, password string) error Set("update_at", now). Where(sq.Eq{"id": userID}) - _, err := query.Exec() - return err + result, err := query.Exec() + if err != nil { + return err + } + + rowCount, err := result.RowsAffected() + if err != nil { + return err + } + + if rowCount < 1 { + return errors.New("user not found") + } + + return nil }