Browse Source

Create scopes on bulk upload errors

pull/2666/head
Manny Dinssa 2 years ago
parent
commit
4da13aaf6b
  1. 6
      app/models/bulk_upload.rb
  2. 4
      app/models/bulk_upload_error.rb

6
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

4
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

Loading…
Cancel
Save