mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Use a strings.Builder to create the idQuery string (#11600)
* Use a strings.Builder to create the idQuery string * Use the query builder
This commit is contained in:
committed by
George Goldberg
parent
c49f755a14
commit
7070b3596b
@@ -7,7 +7,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
@@ -1037,20 +1036,18 @@ func (s SqlTeamStore) GetTeamMembersForExport(userId string) ([]*model.TeamMembe
|
||||
}
|
||||
|
||||
func (s SqlTeamStore) UserBelongsToTeams(userId string, teamIds []string) (bool, *model.AppError) {
|
||||
props := make(map[string]interface{})
|
||||
props["UserId"] = userId
|
||||
idQuery := ""
|
||||
|
||||
for index, teamId := range teamIds {
|
||||
if len(idQuery) > 0 {
|
||||
idQuery += ", "
|
||||
}
|
||||
|
||||
props["teamId"+strconv.Itoa(index)] = teamId
|
||||
idQuery += ":teamId" + strconv.Itoa(index)
|
||||
idQuery := sq.Eq{
|
||||
"UserId": userId,
|
||||
"TeamId": teamIds,
|
||||
"DeleteAt": 0,
|
||||
}
|
||||
|
||||
c, err := s.GetReplica().SelectInt("SELECT Count(*) FROM TeamMembers WHERE UserId = :UserId AND TeamId IN ("+idQuery+") AND DeleteAt = 0", props)
|
||||
query, params, err := s.getQueryBuilder().Select("Count(*)").From("TeamMembers").Where(idQuery).ToSql()
|
||||
if err != nil {
|
||||
return false, model.NewAppError("SqlTeamStore.UserBelongsToTeams", "store.sql_team.user_belongs_to_teams.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
c, err := s.GetReplica().SelectInt(query, params...)
|
||||
if err != nil {
|
||||
return false, model.NewAppError("SqlTeamStore.UserBelongsToTeams", "store.sql_team.user_belongs_to_teams.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user