Browse Source

Handle wrong template and blank template with new failed attribute on bulk upload model

pull/2653/head
Manny Dinssa 2 years ago
parent
commit
5b3f8cc1c4
  1. 20
      app/models/bulk_upload.rb
  2. 4
      app/services/bulk_upload/processor.rb
  3. 5
      db/migrate/20240925095041_add_failed_to_bulk_uploads.rb
  4. 3
      db/schema.rb

20
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?

4
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

5
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

3
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

Loading…
Cancel
Save