From f211373ffafcce1923421fe5bc10e033bef8a356 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 15 Oct 2021 14:57:40 +0100 Subject: [PATCH] Use scopes for bulk status lookups --- app/controllers/case_logs_controller.rb | 4 ++-- app/models/case_log.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 2a0c6b84a..f3753058e 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -3,8 +3,8 @@ class CaseLogsController < ApplicationController before_action :authenticate, if: :json_api_request? def index - @completed_case_logs = CaseLog.where(status: 2) - @in_progress_case_logs = CaseLog.where(status: 1) + @completed_case_logs = CaseLog.completed + @in_progress_case_logs = CaseLog.in_progress end def create diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 64c1cdb95..42a020fd4 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -28,6 +28,8 @@ end class CaseLog < ApplicationRecord include Discard::Model default_scope -> { kept } + scope :in_progress, -> { where(status: "in_progress") } + scope :completed, -> { where(status: "completed") } validate :instance_validations before_save :update_status!