From fbc6926402bad4368af16b8757be729799c16ecb Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 28 Dec 2024 18:16:36 +0100 Subject: [PATCH] Run Rubocop autocorrect on app/queries --- app/queries/expenses/total_query.rb | 8 +++++--- app/queries/groups/summary_query.rb | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/queries/expenses/total_query.rb b/app/queries/expenses/total_query.rb index 7dc47d6..81feea7 100644 --- a/app/queries/expenses/total_query.rb +++ b/app/queries/expenses/total_query.rb @@ -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 diff --git a/app/queries/groups/summary_query.rb b/app/queries/groups/summary_query.rb index 0736496..595b6e1 100644 --- a/app/queries/groups/summary_query.rb +++ b/app/queries/groups/summary_query.rb @@ -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