Run Rubocop autocorrect on app/queries

This commit is contained in:
Manuel Bustillo 2024-12-28 18:16:36 +01:00
parent 19dcb551fa
commit fbc6926402
2 changed files with 17 additions and 5 deletions

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo
module Expenses
@ -16,7 +18,7 @@ module Expenses
private
def query
<<~SQL
<<~SQL.squish
WITH guest_count AS (#{guest_count_per_status}),
expense_summary AS (#{expense_summary})
SELECT guest_count.confirmed as confirmed_guests,
@ -28,7 +30,7 @@ module Expenses
end
def expense_summary
<<~SQL
<<~SQL.squish
SELECT coalesce(sum(amount) filter (where pricing_type = 'fixed'), 0) as fixed,
coalesce(sum(amount) filter (where pricing_type = 'per_person'), 0) as variable
FROM expenses
@ -37,7 +39,7 @@ module Expenses
end
def guest_count_per_status
<<~SQL
<<~SQL.squish
SELECT COALESCE(count(*) filter(where status = #{Guest.statuses['confirmed']}), 0) as confirmed,
COALESCE(count(*) filter(where status IN (#{Guest.statuses.values_at('confirmed', 'invited', 'tentative').join(',')})), 0) as projected
FROM guests

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo
module Groups
@ -9,13 +11,21 @@ module Groups
:icon,
:parent_id,
:color,
*count_expressions
)
end
private
def count_expressions
[
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'),
)
Arel.sql('count(*) filter (where status = 40) as tentative')
]
end
end
end