mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Updated ListQueries method in DB layer
This commit is contained in:
parent
390e0565d0
commit
de9a1540d0
@ -358,12 +358,20 @@ func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions
|
||||
if opt.OnlyObserverCanRun {
|
||||
sql += " AND q.observer_can_run=true"
|
||||
}
|
||||
|
||||
args := []interface{}{false, aggregatedStatsTypeQuery}
|
||||
whereClause := " AND team_id_char = ''"
|
||||
if opt.TeamID != nil {
|
||||
args = append(args, fmt.Sprint(*opt.TeamID))
|
||||
whereClause = " AND team_id_char = ?"
|
||||
}
|
||||
sql += whereClause
|
||||
|
||||
sql = appendListOptionsToSQL(sql, &opt.ListOptions)
|
||||
|
||||
results := []*fleet.Query{}
|
||||
|
||||
if err := sqlx.SelectContext(ctx, ds.reader(ctx), &results, sql, false, aggregatedStatsTypeQuery); err != nil {
|
||||
fmt.Println(err)
|
||||
if err := sqlx.SelectContext(ctx, ds.reader(ctx), &results, sql, args...); err != nil {
|
||||
return nil, ctxerr.Wrap(ctx, err, "listing queries")
|
||||
}
|
||||
|
||||
|
@ -761,6 +761,9 @@ func (l ListOptions) UsesCursorPagination() bool {
|
||||
type ListQueryOptions struct {
|
||||
ListOptions
|
||||
|
||||
// TeamID which team the queries belong to. If teamID is nil, then it is assumed the 'global'
|
||||
// team
|
||||
TeamID *uint
|
||||
OnlyObserverCanRun bool
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user