From 4da13aaf6be528a8b8e5b6a15c27d8bd24c383f2 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:00:42 +0100 Subject: [PATCH] Create scopes on bulk upload errors --- app/models/bulk_upload.rb | 6 +++--- app/models/bulk_upload_error.rb | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index dc862529e..ad76c2192 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -47,11 +47,11 @@ class BulkUpload < ApplicationRecord return :logs_uploaded_with_errors if bulk_upload_errors.any? end - if bulk_upload_errors.any? { |error| error.category == "setup" } + if bulk_upload_errors.important.any? :important_errors - elsif bulk_upload_errors.any? { |error| error.category.nil? || error.category == "not_answered" } + elsif bulk_upload_errors.critical.any? :critical_errors - elsif bulk_upload_errors.any? { |error| error.category == "soft_validation" } + elsif bulk_upload_errors.potential.any? :potential_errors else :logs_uploaded_no_errors diff --git a/app/models/bulk_upload_error.rb b/app/models/bulk_upload_error.rb index c9ca14b0f..154fca2fc 100644 --- a/app/models/bulk_upload_error.rb +++ b/app/models/bulk_upload_error.rb @@ -4,4 +4,8 @@ class BulkUploadError < ApplicationRecord scope :order_by_row, -> { order("row::integer ASC") } scope :order_by_cell, -> { order(Arel.sql("LPAD(cell, 10, '0')")) } scope :order_by_col, -> { order(Arel.sql("LPAD(col, 10, '0')")) } + scope :important, -> { where(category: "setup") } + scope :potential, -> { where(category: "soft_validation") } + scope :critical, -> { where(category: nil).or(where.not(category: %w[setup soft_validation])) } + scope :critical_or_important, -> { critical.or(important) } end