Skip to content

Commit

Permalink
fix counting
Browse files Browse the repository at this point in the history
  • Loading branch information
loeffel-io committed Nov 13, 2020
1 parent 26dd4c6 commit d954820
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions database/basic/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (database *Database) DeleteTeam(connection *gorm.DB, team *makeless_go_mode
func (database *Database) IsTeamUser(connection *gorm.DB, team *makeless_go_model.Team, user *makeless_go_model.User) (bool, error) {
var count int64

return count == 1, connection.
Raw("SELECT COUNT(*) FROM team_users WHERE team_users.team_id = ? AND team_users.user_id = ? LIMIT 1", team.GetId(), user.GetId()).
return count >= 1, connection.
Raw("SELECT COUNT(*) FROM team_users WHERE team_users.team_id = ? AND team_users.user_id = ?", team.GetId(), user.GetId()).
Count(&count).
Error
}
Expand All @@ -113,8 +113,8 @@ func (database *Database) IsTeamUser(connection *gorm.DB, team *makeless_go_mode
func (database *Database) IsTeamRole(connection *gorm.DB, role string, team *makeless_go_model.Team, user *makeless_go_model.User) (bool, error) {
var count int64

return count == 1, connection.
Raw("SELECT COUNT(*) FROM team_users WHERE team_users.team_id = ? AND team_users.user_id = ? AND team_users.role = ? LIMIT 1", team.GetId(), user.GetId(), role).
return count >= 1, connection.
Raw("SELECT COUNT(*) FROM team_users WHERE team_users.team_id = ? AND team_users.user_id = ? AND team_users.role = ?", team.GetId(), user.GetId(), role).
Count(&count).
Error
}
Expand All @@ -123,8 +123,8 @@ func (database *Database) IsTeamRole(connection *gorm.DB, role string, team *mak
func (database *Database) IsTeamCreator(connection *gorm.DB, team *makeless_go_model.Team, user *makeless_go_model.User) (bool, error) {
var count int64

return count == 1, connection.
Raw("SELECT COUNT(*) FROM teams WHERE teams.id = ? AND teams.user_id = ? LIMIT 1", team.GetId(), user.GetId()).
return count >= 1, connection.
Raw("SELECT COUNT(*) FROM teams WHERE teams.id = ? AND teams.user_id = ?", team.GetId(), user.GetId()).
Count(&count).
Error
}
Expand All @@ -142,7 +142,7 @@ func (database *Database) IsNotTeamCreator(connection *gorm.DB, team *makeless_g
func (database *Database) IsModelTeam(connection *gorm.DB, team *makeless_go_model.Team, model interface{}) (bool, error) {
var count int64

return count == 1, connection.
return count >= 1, connection.
Model(model).
Select("COUNT(*)").
Where("team_id = ?", team.GetId()).
Expand Down
2 changes: 1 addition & 1 deletion database/basic/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (database *Database) CreateUser(connection *gorm.DB, user *makeless_go_mode
func (database *Database) IsModelUser(connection *gorm.DB, user *makeless_go_model.User, model interface{}) (bool, error) {
var count int64

return count == 1, connection.
return count >= 1, connection.
Model(model).
Select("COUNT(*)").
Where("user_id = ?", user.GetId()).
Expand Down

0 comments on commit d954820

Please sign in to comment.