Manuel Bustillo cc3c8fdd63
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 39s
Add copyright notice / copyright_notice (pull_request) Successful in 1m26s
Run unit tests / unit_tests (pull_request) Successful in 1m54s
Improve documentation of groups endpoint
2024-11-15 19:46:47 +01:00

32 lines
822 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