2025-01-13 20:38:47 +00:00
|
|
|
# Copyright (C) 2024 Manuel Bustillo
|
|
|
|
|
2025-01-13 21:37:02 +01:00
|
|
|
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
2024-11-13 07:59:07 +00:00
|
|
|
|
2024-12-28 18:37:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-13 08:57:20 +01:00
|
|
|
module Groups
|
|
|
|
class SummaryQuery
|
|
|
|
def call
|
2024-12-08 11:39:50 +01:00
|
|
|
Group.left_joins(:guests).group(:id).pluck_to_hash(
|
|
|
|
:id,
|
|
|
|
:name,
|
|
|
|
:icon,
|
|
|
|
:parent_id,
|
|
|
|
:color,
|
2024-12-28 18:16:36 +01:00
|
|
|
*count_expressions
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def count_expressions
|
|
|
|
[
|
2024-12-08 11:39:50 +01:00
|
|
|
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'),
|
2024-12-28 18:16:36 +01:00
|
|
|
Arel.sql('count(*) filter (where status = 40) as tentative')
|
|
|
|
]
|
2024-11-13 08:57:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|