From f6850b54276fdb0d3b1f7f852353896b00493e09 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Mon, 1 Sep 2025 14:09:00 +0300 Subject: [PATCH] add completed submitters verification method --- app/jobs/process_submitter_completion_job.rb | 9 +++++++- app/models/completed_submitter.rb | 21 ++++++++++--------- ...fication_method_to_completed_submitters.rb | 7 +++++++ db/schema.rb | 3 ++- 4 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20250901110606_add_verification_method_to_completed_submitters.rb diff --git a/app/jobs/process_submitter_completion_job.rb b/app/jobs/process_submitter_completion_job.rb index 49f79fcf..ab98895f 100644 --- a/app/jobs/process_submitter_completion_job.rb +++ b/app/jobs/process_submitter_completion_job.rb @@ -38,12 +38,19 @@ class ProcessSubmitterCompletionJob submission = submitter.submission + complete_verification_events, sms_events = + submitter.submission_events.where(event_type: %i[send_sms send_2fa_sms complete_verification]) + .partition { |e| e.event_type == 'complete_verification' } + + complete_verification_event = complete_verification_events.first + completed_submitter.assign_attributes( submission_id: submitter.submission_id, account_id: submission.account_id, template_id: submission.template_id, source: submission.source, - sms_count: submitter.submission_events.where(event_type: %w[send_sms send_2fa_sms]).count, + sms_count: sms_events.size, + verification_method: complete_verification_event&.data&.dig('method'), completed_at: submitter.completed_at ) diff --git a/app/models/completed_submitter.rb b/app/models/completed_submitter.rb index 6ada62f3..ae13647a 100644 --- a/app/models/completed_submitter.rb +++ b/app/models/completed_submitter.rb @@ -4,16 +4,17 @@ # # Table name: completed_submitters # -# id :bigint not null, primary key -# completed_at :datetime not null -# sms_count :integer not null -# source :string not null -# created_at :datetime not null -# updated_at :datetime not null -# account_id :bigint not null -# submission_id :bigint not null -# submitter_id :bigint not null -# template_id :bigint +# id :bigint not null, primary key +# completed_at :datetime not null +# sms_count :integer not null +# source :string not null +# verification_method :string +# created_at :datetime not null +# updated_at :datetime not null +# account_id :bigint not null +# submission_id :bigint not null +# submitter_id :bigint not null +# template_id :bigint # # Indexes # diff --git a/db/migrate/20250901110606_add_verification_method_to_completed_submitters.rb b/db/migrate/20250901110606_add_verification_method_to_completed_submitters.rb new file mode 100644 index 00000000..31d48047 --- /dev/null +++ b/db/migrate/20250901110606_add_verification_method_to_completed_submitters.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddVerificationMethodToCompletedSubmitters < ActiveRecord::Migration[8.0] + def change + add_column :completed_submitters, :verification_method, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index bb59b018..9b5ee95b 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[8.0].define(version: 2025_08_31_125322) do +ActiveRecord::Schema[8.0].define(version: 2025_09_01_110606) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "plpgsql" @@ -117,6 +117,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_08_31_125322) do t.datetime "completed_at", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "verification_method" t.index ["account_id"], name: "index_completed_submitters_on_account_id" t.index ["submitter_id"], name: "index_completed_submitters_on_submitter_id", unique: true end