From 598c6d9636b405cea041066c1f2b46195786598f Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:55:59 +0100 Subject: [PATCH] Handle wrong template and blank template --- app/components/bulk_upload_summary_component.rb | 4 ++-- app/models/bulk_upload.rb | 2 ++ app/services/bulk_upload/processor.rb | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/components/bulk_upload_summary_component.rb b/app/components/bulk_upload_summary_component.rb index ad975074d..6f7cbede9 100644 --- a/app/components/bulk_upload_summary_component.rb +++ b/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" diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index b1ba42135..e82a71935 100644 --- a/app/models/bulk_upload.rb +++ b/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? diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index 3fbb1e2d4..c5d1b74eb 100644 --- a/app/services/bulk_upload/processor.rb +++ b/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