Feature: Website SDK (#653)
Add SDK functions Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
# Table name: accounts
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# locale :integer default("English")
|
||||
# locale :integer default("eng")
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# id :integer not null, primary key
|
||||
# additional_attributes :jsonb
|
||||
# email :string
|
||||
# identifier :string
|
||||
# name :string
|
||||
# phone_number :string
|
||||
# pubsub_token :string
|
||||
@@ -14,8 +15,10 @@
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_contacts_on_account_id (account_id)
|
||||
# index_contacts_on_pubsub_token (pubsub_token) UNIQUE
|
||||
# index_contacts_on_account_id (account_id)
|
||||
# index_contacts_on_pubsub_token (pubsub_token) UNIQUE
|
||||
# uniq_email_per_account_contact (email,account_id) UNIQUE
|
||||
# uniq_identifier_per_account_contact (identifier,account_id) UNIQUE
|
||||
#
|
||||
|
||||
class Contact < ApplicationRecord
|
||||
@@ -23,6 +26,8 @@ class Contact < ApplicationRecord
|
||||
include Avatarable
|
||||
include AvailabilityStatusable
|
||||
validates :account_id, presence: true
|
||||
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
|
||||
validates :identifier, allow_blank: true, uniqueness: { scope: [:account_id] }
|
||||
|
||||
belongs_to :account
|
||||
has_many :conversations, dependent: :destroy
|
||||
@@ -30,6 +35,8 @@ class Contact < ApplicationRecord
|
||||
has_many :inboxes, through: :contact_inboxes
|
||||
has_many :messages, dependent: :destroy
|
||||
|
||||
before_validation :downcase_email
|
||||
|
||||
def get_source_id(inbox_id)
|
||||
contact_inboxes.find_by!(inbox_id: inbox_id).source_id
|
||||
end
|
||||
@@ -49,4 +56,8 @@ class Contact < ApplicationRecord
|
||||
name: name
|
||||
}
|
||||
end
|
||||
|
||||
def downcase_email
|
||||
email.downcase! if email.present?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user