Files
docuseal/app/models/submitter.rb
T

60 lines
1.4 KiB
Ruby
Raw Normal View History

2023-06-13 00:29:07 +03:00
# frozen_string_literal: true
# == Schema Information
#
# Table name: submitters
#
# id :bigint not null, primary key
# completed_at :datetime
# email :string not null
# ip :string
# opened_at :datetime
# sent_at :datetime
# slug :string not null
# ua :string
# uuid :string not null
2023-07-09 16:27:07 +03:00
# values :text not null
2023-06-13 00:29:07 +03:00
# created_at :datetime not null
# updated_at :datetime not null
# submission_id :bigint not null
#
# Indexes
#
# index_submitters_on_email (email)
# index_submitters_on_slug (slug) UNIQUE
# index_submitters_on_submission_id (submission_id)
#
# Foreign Keys
#
# fk_rails_... (submission_id => submissions.id)
#
class Submitter < ApplicationRecord
belongs_to :submission
attribute :values, :string, default: -> { {} }
2023-07-14 22:33:42 +03:00
attribute :slug, :string, default: -> { SecureRandom.base58(14) }
2023-06-13 00:29:07 +03:00
serialize :values, JSON
has_many_attached :documents
has_many_attached :attachments
2023-07-01 13:16:07 +03:00
has_many :document_generation_events, dependent: :destroy
2023-06-13 00:29:07 +03:00
def status
if completed_at?
'completed'
elsif opened_at?
'opened'
elsif sent_at?
'sent'
else
'awaiting'
end
end
2023-06-30 01:26:13 +03:00
def status_event_at
completed_at || opened_at || sent_at || created_at
end
2023-06-13 00:29:07 +03:00
end