add submitter account_id
This commit is contained in:
@@ -82,6 +82,8 @@ class StartFormController < ApplicationController
|
|||||||
template_submitters: template.submitters,
|
template_submitters: template.submitters,
|
||||||
source: :link)
|
source: :link)
|
||||||
|
|
||||||
|
submitter.account_id = submitter.submission.account_id
|
||||||
|
|
||||||
submitter
|
submitter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,17 @@
|
|||||||
# values :text not null
|
# values :text not null
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
|
# account_id :bigint
|
||||||
# external_id :string
|
# external_id :string
|
||||||
# submission_id :bigint not null
|
# submission_id :bigint not null
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
# index_submitters_on_email (email)
|
# index_submitters_on_account_id_and_id (account_id,id)
|
||||||
# index_submitters_on_external_id (external_id)
|
# index_submitters_on_email (email)
|
||||||
# index_submitters_on_slug (slug) UNIQUE
|
# index_submitters_on_external_id (external_id)
|
||||||
# index_submitters_on_submission_id (submission_id)
|
# index_submitters_on_slug (slug) UNIQUE
|
||||||
|
# index_submitters_on_submission_id (submission_id)
|
||||||
#
|
#
|
||||||
# Foreign Keys
|
# Foreign Keys
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddAccountIdToSubmitters < ActiveRecord::Migration[7.1]
|
||||||
|
def change
|
||||||
|
add_reference :submitters, :account, index: false, null: true
|
||||||
|
|
||||||
|
add_index :submitters, %i[account_id id]
|
||||||
|
end
|
||||||
|
end
|
||||||
+3
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.1].define(version: 2024_08_01_125558) do
|
ActiveRecord::Schema[7.1].define(version: 2024_08_16_064633) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@@ -243,6 +243,8 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_01_125558) do
|
|||||||
t.string "external_id"
|
t.string "external_id"
|
||||||
t.text "preferences", null: false
|
t.text "preferences", null: false
|
||||||
t.text "metadata", null: false
|
t.text "metadata", null: false
|
||||||
|
t.bigint "account_id"
|
||||||
|
t.index ["account_id", "id"], name: "index_submitters_on_account_id_and_id"
|
||||||
t.index ["email"], name: "index_submitters_on_email"
|
t.index ["email"], name: "index_submitters_on_email"
|
||||||
t.index ["external_id"], name: "index_submitters_on_external_id"
|
t.index ["external_id"], name: "index_submitters_on_external_id"
|
||||||
t.index ["slug"], name: "index_submitters_on_slug", unique: true
|
t.index ["slug"], name: "index_submitters_on_slug", unique: true
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ module Submissions
|
|||||||
|
|
||||||
submission.submitters.new(email: normalize_email(email),
|
submission.submitters.new(email: normalize_email(email),
|
||||||
uuid: template.submitters.first['uuid'],
|
uuid: template.submitters.first['uuid'],
|
||||||
|
account_id: user.account_id,
|
||||||
preferences:,
|
preferences:,
|
||||||
sent_at: mark_as_sent ? Time.current : nil)
|
sent_at: mark_as_sent ? Time.current : nil)
|
||||||
|
|
||||||
|
|||||||
@@ -155,16 +155,14 @@ module Submissions
|
|||||||
submitter_preferences = Submitters.normalize_preferences(submission.account, user, attrs)
|
submitter_preferences = Submitters.normalize_preferences(submission.account, user, attrs)
|
||||||
values = attrs[:values] || {}
|
values = attrs[:values] || {}
|
||||||
|
|
||||||
phone_field_uuid =
|
phone_field_uuid = find_phone_field(submission, values)&.dig('uuid')
|
||||||
(submission.template_fields || submission.template.fields).find do |f|
|
|
||||||
values[f['uuid']].present? && f['type'] == 'phone'
|
|
||||||
end&.dig('uuid')
|
|
||||||
|
|
||||||
submitter =
|
submitter =
|
||||||
submission.submitters.new(
|
submission.submitters.new(
|
||||||
email:,
|
email:,
|
||||||
phone: (attrs[:phone] || values[phone_field_uuid]).to_s.gsub(/[^0-9+]/, ''),
|
phone: (attrs[:phone] || values[phone_field_uuid]).to_s.gsub(/[^0-9+]/, ''),
|
||||||
name: attrs[:name],
|
name: attrs[:name],
|
||||||
|
account_id: user.account_id,
|
||||||
external_id: attrs[:external_id].presence || attrs[:application_key],
|
external_id: attrs[:external_id].presence || attrs[:application_key],
|
||||||
completed_at: attrs[:completed].present? ? Time.current : nil,
|
completed_at: attrs[:completed].present? ? Time.current : nil,
|
||||||
values: values.except(phone_field_uuid),
|
values: values.except(phone_field_uuid),
|
||||||
@@ -183,6 +181,12 @@ module Submissions
|
|||||||
submitter
|
submitter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_phone_field(submission, values)
|
||||||
|
(submission.template_fields || submission.template.fields).find do |f|
|
||||||
|
values[f['uuid']].present? && f['type'] == 'phone'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assign_completed_attributes(submitter)
|
def assign_completed_attributes(submitter)
|
||||||
submitter.values = Submitters::SubmitValues.merge_default_values(submitter)
|
submitter.values = Submitters::SubmitValues.merge_default_values(submitter)
|
||||||
submitter.values = Submitters::SubmitValues.merge_formula_values(submitter)
|
submitter.values = Submitters::SubmitValues.merge_formula_values(submitter)
|
||||||
|
|||||||
Reference in New Issue
Block a user