wedding-planner/app/queries/groups/summary_query.rb
Manuel Bustillo 4be1fc6cad
All checks were successful
Check usage of free licenses / build-static-assets (pull_request) Successful in 2m24s
Add copyright notice / copyright_notice (pull_request) Successful in 5m47s
Run unit tests / unit_tests (pull_request) Successful in 4m14s
Add copyright notice
2024-11-13 07:59:07 +00:00

32 lines
828 B
Ruby

# Copyright (C) 2024 Manuel Bustillo
module Groups
class SummaryQuery
def call
ActiveRecord::Base.connection.execute(query).to_a
end
private
def query
<<~SQL.squish
SELECT#{' '}
groups.id,
groups.name,
groups.icon,
groups.parent_id,
groups.color,
count(*) filter (where status IS NOT NULL) as total,
count(*) filter (where status = 0) as considered,
count(*) filter (where status = 10) as invited,
count(*) filter (where status = 20) as confirmed,
count(*) filter (where status = 30) as declined,
count(*) filter (where status = 40) as tentative
FROM groups
LEFT JOIN guests on groups.id = guests.group_id
GROUP BY groups.id
SQL
end
end
end