mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Add host and user counts to list teams response (#668)
This commit is contained in:
parent
9ade086448
commit
af802dc15f
2 changed files with 8 additions and 1 deletions
|
|
@ -81,7 +81,10 @@ func (d *Datastore) SaveTeam(team *kolide.Team) (*kolide.Team, error) {
|
|||
// kolide.ListOptions
|
||||
func (d *Datastore) ListTeams(opt kolide.ListOptions) ([]*kolide.Team, error) {
|
||||
query := `
|
||||
SELECT * FROM teams
|
||||
SELECT *,
|
||||
(SELECT count(*) FROM user_teams WHERE team_id = id) AS user_count,
|
||||
(SELECT count(*) FROM hosts WHERE team_id = id) AS host_count
|
||||
FROM teams
|
||||
WHERE TRUE
|
||||
`
|
||||
query, params := searchLike(query, nil, opt.MatchQuery, teamSearchColumns...)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,12 @@ type Team struct {
|
|||
|
||||
// Derived from JOINs
|
||||
|
||||
// UserCount is the count of users with explicit roles on this team.
|
||||
UserCount int `json:"user_count" db:"user_count"`
|
||||
// Users is the users that have a role on this team.
|
||||
Users []TeamUser `json:"users,omitempty"`
|
||||
// UserCount is the count of hosts assigned to this team.
|
||||
HostCount int `json:"host_count" db:"host_count"`
|
||||
// Hosts are the hosts assigned to the team.
|
||||
Hosts []Host `json:"hosts,omitempty"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue