From ad165e1df9d1ee4b841aad9db4da6523ed7aabad Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 26 Jan 2023 15:36:21 +0000 Subject: [PATCH] refactor: move safe navigator and add shared org_params to log --- app/controllers/lettings_logs_controller.rb | 8 +++----- app/controllers/logs_controller.rb | 1 - app/controllers/sales_logs_controller.rb | 7 ------- app/services/filter_service.rb | 2 +- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index 0e2e4470d..e7d233f87 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -102,11 +102,9 @@ class LettingsLogsController < LogsController end def org_params - { - "owning_organisation_id" => current_user.organisation.id, - "managing_organisation_id" => current_user.organisation.id, - "created_by_id" => current_user.id, - } + super.merge( + { "managing_organisation_id" => current_user.organisation.id }, + ) end private diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index 083d40178..603608241 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -63,7 +63,6 @@ private owning_organisation_id = current_user.organisation.holds_own_stock? ? current_user.organisation.id : nil { "owning_organisation_id" => owning_organisation_id, - "managing_organisation_id" => current_user.organisation.id, "created_by_id" => current_user.id, } end diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index cf770576f..8a6c9937f 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -43,11 +43,4 @@ class SalesLogsController < LogsController def permitted_log_params params.require(:sales_log).permit(SalesLog.editable_fields) end - - def org_params - { - "owning_organisation_id" => current_user.organisation.id, - "created_by_id" => current_user.id, - } - end end diff --git a/app/services/filter_service.rb b/app/services/filter_service.rb index 3c0a5912d..4ef3a582c 100644 --- a/app/services/filter_service.rb +++ b/app/services/filter_service.rb @@ -18,7 +18,7 @@ class FilterService end logs = logs.order(created_at: :desc) if user.support? - if logs&.first.lettings? + if logs.first&.lettings? logs.all.includes(:owning_organisation, :managing_organisation) else logs.all.includes(:owning_organisation)