diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index e82a71935..b17d6d289 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -3,14 +3,14 @@ class BulkUpload < ApplicationRecord enum rent_type_fix_status: { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" } enum status: { - blank_template: 0, - wrong_template: 1, - important_errors: 2, - critical_errors: 3, - potential_errors: 4, - logs_uploaded_with_errors: 5, - errors_fixed_in_service: 6, - logs_uploaded_no_errors: 7, + logs_uploaded_no_errors: 0, + blank_template: 1, + wrong_template: 2, + important_errors: 3, + critical_errors: 4, + potential_errors: 5, + logs_uploaded_with_errors: 6, + errors_fixed_in_service: 7, } belongs_to :user @@ -51,8 +51,8 @@ class BulkUpload < ApplicationRecord end def status - return :wrong_template if choice == "wrong_template" - return :blank_template if choice == "blank_template" + return :blank_template if failed == 1 + return :wrong_template if failed == 2 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 c5d1b74eb..71ee18ab5 100644 --- a/app/services/bulk_upload/processor.rb +++ b/app/services/bulk_upload/processor.rb @@ -147,9 +147,9 @@ private 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") + @bulk_upload.update!(failed: 1) elsif validator.errors.full_messages.include?("Incorrect number of fields, please ensure you have used the correct template") - @bulk_upload.update!(choice: "wrong_template") + @bulk_upload.update!(failed: 2) end send_failure_mail(errors: validator.errors.full_messages) end diff --git a/db/migrate/20240925095041_add_failed_to_bulk_uploads.rb b/db/migrate/20240925095041_add_failed_to_bulk_uploads.rb new file mode 100644 index 000000000..82cc219bd --- /dev/null +++ b/db/migrate/20240925095041_add_failed_to_bulk_uploads.rb @@ -0,0 +1,5 @@ +class AddFailedToBulkUploads < ActiveRecord::Migration[7.0] + def change + add_column :bulk_uploads, :failed, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 4d6f18b84..31c7ac515 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_09_23_145326) do +ActiveRecord::Schema[7.0].define(version: 2024_09_25_095041) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -44,6 +44,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_09_23_145326) do t.string "rent_type_fix_status", default: "not_applied" t.integer "organisation_id" t.integer "moved_user_id" + t.integer "failed" t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["user_id"], name: "index_bulk_uploads_on_user_id" end