Browse Source

Handle wrong template and blank template

pull/2653/head
Manny Dinssa 2 years ago
parent
commit
598c6d9636
  1. 4
      app/components/bulk_upload_summary_component.rb
  2. 2
      app/models/bulk_upload.rb
  3. 11
      app/services/bulk_upload/processor.rb

4
app/components/bulk_upload_summary_component.rb

@ -59,7 +59,7 @@ class BulkUploadSummaryComponent < ViewComponent::Base
end
def view_error_report_link(controller, bulk_upload)
return nil if %w[errors_fixed_in_service logs_uploaded_with_errors logs_uploaded_no_errors].include?(bulk_upload.status.to_s)
return nil if %w[errors_fixed_in_service logs_uploaded_with_errors logs_uploaded_no_errors wrong_template blank_template].include?(bulk_upload.status.to_s)
case controller.controller_name
when "lettings_logs"
@ -74,7 +74,7 @@ class BulkUploadSummaryComponent < ViewComponent::Base
end
def view_logs_link(controller, bulk_upload)
return nil if %w[errors_fixed_in_service logs_uploaded_no_errors].include?(bulk_upload.status.to_s)
return nil if %w[errors_fixed_in_service logs_uploaded_no_errors wrong_template blank_template].include?(bulk_upload.status.to_s)
case controller.controller_name
when "lettings_logs"

2
app/models/bulk_upload.rb

@ -51,6 +51,8 @@ class BulkUpload < ApplicationRecord
end
def status
return :wrong_template if choice == "wrong_template"
return :blank_template if choice == "blank_template"
return :logs_uploaded_no_errors if bulk_upload_errors.none?
if logs.visible.exists?

11
app/services/bulk_upload/processor.rb

@ -11,7 +11,7 @@ class BulkUpload::Processor
download
@bulk_upload.update!(total_logs_count: validator.total_logs_count)
return send_failure_mail(errors: validator.errors.full_messages) if validator.invalid?
return handle_invalid_validator if validator.invalid?
validator.call
@ -144,4 +144,13 @@ private
raise "Validator not found for #{bulk_upload.log_type}"
end
end
def handle_invalid_validator
if validator.errors.full_messages.include?("Template is blank - The template must be filled in for us to create the logs and check if data is correct.")
@bulk_upload.update!(choice: "blank_template")
elsif validator.errors.full_messages.include?("Incorrect number of fields, please ensure you have used the correct template")
@bulk_upload.update!(choice: "wrong_template")
end
send_failure_mail(errors: validator.errors.full_messages)
end
end

Loading…
Cancel
Save