diff --git a/repository/account/account.go b/repository/account/account.go index 64021d8..3db1055 100644 --- a/repository/account/account.go +++ b/repository/account/account.go @@ -3,11 +3,12 @@ package account import ( "context" "database/sql" + "errors" "fmt" - "github.com/google/uuid" "gitea.pena/SQuiz/common/dal/sqlcgen" "gitea.pena/SQuiz/common/model" "gitea.pena/SQuiz/common/pj_errors" + "github.com/google/uuid" "strconv" ) @@ -456,3 +457,18 @@ func (r *AccountRepository) UpdateLeadTarget(ctx context.Context, req model.Lead InviteLink: row.Invitelink, }, nil } + +func (r *AccountRepository) CheckLeadTargetOwner(ctx context.Context, accountID string, leadID int64) (bool, error) { + id, err := r.queries.CheckLeadTargetOwner(ctx, sqlcgen.CheckLeadTargetOwnerParams{ + Accountid: accountID, + ID: leadID, + }) + + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return false, nil + } + return false, err + } + return accountID == id, nil +}