Manuel Bustillo 20127398c6
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 1m10s
Add copyright notice / copyright_notice (pull_request) Successful in 1m35s
Run unit tests / unit_tests (pull_request) Successful in 5m11s
Fix summary query to leverage ActsAsTenant scopes
2024-12-08 11:39:50 +01:00

22 lines
669 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
module Groups
class SummaryQuery
def call
Group.left_joins(:guests).group(:id).pluck_to_hash(
:id,
:name,
:icon,
:parent_id,
:color,
Arel.sql('count(*) filter (where status IS NOT NULL) as total'),
Arel.sql('count(*) filter (where status = 0) as considered'),
Arel.sql('count(*) filter (where status = 10) as invited'),
Arel.sql('count(*) filter (where status = 20) as confirmed'),
Arel.sql('count(*) filter (where status = 30) as declined'),
Arel.sql('count(*) filter (where status = 40) as tentative'),
)
end
end
end