Skip to content

Commit aafb19f

Browse files
authored
fix: Query projects with issues (#111)
1 parent 09e7fc0 commit aafb19f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/controllers/api/v1/projects_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ class ProjectsController < BaseController
44
# GET /api/v1/projects
55
# Optional query params:
66
# - with_drift: "true" to filter only projects with drifting environments
7+
# - with_issues: "true" to filter projects with drift OR error environments
78
def index
89
projects = Project.includes(:environments).order(:name)
910

10-
if params[:with_drift] == "true"
11+
if params[:with_issues] == "true"
12+
projects = projects.joins(:environments).where(environments: { status: [ :drift, :error ] }).distinct
13+
elsif params[:with_drift] == "true"
1114
projects = projects.joins(:environments).where(environments: { status: :drift }).distinct
1215
end
1316

@@ -31,7 +34,8 @@ def project_json(project, include_environments: false)
3134
aggregated_status: project.aggregated_status,
3235
last_checked_at: project.last_checked_at,
3336
environment_count: project.environments.count,
34-
drift_environment_count: project.environments.where(status: :drift).count
37+
drift_environment_count: project.environments.where(status: :drift).count,
38+
error_environment_count: project.environments.where(status: :error).count
3539
}
3640

3741
if include_environments

0 commit comments

Comments
 (0)