add submission tracking events
This commit is contained in:
@@ -32,6 +32,7 @@ class Submission < ApplicationRecord
|
||||
belongs_to :created_by_user, class_name: 'User', optional: true
|
||||
|
||||
has_many :submitters, dependent: :destroy
|
||||
has_many :submission_events, dependent: :destroy
|
||||
|
||||
serialize :template_fields, JSON
|
||||
serialize :template_schema, JSON
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: submission_events
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# data :text not null
|
||||
# event_timestamp :datetime not null
|
||||
# event_type :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# submission_id :bigint not null
|
||||
# submitter_id :bigint
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_submission_events_on_submission_id (submission_id)
|
||||
# index_submission_events_on_submitter_id (submitter_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (submission_id => submissions.id)
|
||||
# fk_rails_... (submitter_id => submitters.id)
|
||||
#
|
||||
class SubmissionEvent < ApplicationRecord
|
||||
belongs_to :submission
|
||||
belongs_to :submitter, optional: true
|
||||
|
||||
attribute :data, :string, default: -> { {} }
|
||||
attribute :event_timestamp, :datetime, default: -> { Time.current }
|
||||
|
||||
serialize :data, JSON
|
||||
|
||||
before_validation :set_submission_id, on: :create
|
||||
|
||||
enum :event_type, {
|
||||
send_email: 'send_email',
|
||||
send_sms: 'send_sms',
|
||||
open_email: 'open_email',
|
||||
click_email: 'click_email',
|
||||
click_sms: 'click_sms',
|
||||
start_form: 'start_form',
|
||||
view_form: 'view_form',
|
||||
complete_form: 'complete_form'
|
||||
}, scope: false
|
||||
|
||||
private
|
||||
|
||||
def set_submission_id
|
||||
self.submission_id = submitter&.submission_id
|
||||
end
|
||||
end
|
||||
@@ -44,6 +44,7 @@ class Submitter < ApplicationRecord
|
||||
has_many_attached :attachments
|
||||
|
||||
has_many :document_generation_events, dependent: :destroy
|
||||
has_many :submission_events, dependent: :destroy
|
||||
|
||||
def status
|
||||
if completed_at?
|
||||
|
||||
Reference in New Issue
Block a user