feat: Add CSAT response APIs (#2503)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -34,6 +34,7 @@ class Account < ApplicationRecord
|
||||
has_many :account_users, dependent: :destroy
|
||||
has_many :agent_bot_inboxes, dependent: :destroy
|
||||
has_many :agent_bots, dependent: :destroy
|
||||
has_many :csat_survey_responses, dependent: :destroy
|
||||
has_many :data_imports, dependent: :destroy
|
||||
has_many :users, through: :account_users
|
||||
has_many :inboxes, dependent: :destroy
|
||||
|
||||
@@ -39,6 +39,7 @@ class Contact < ApplicationRecord
|
||||
belongs_to :account
|
||||
has_many :conversations, dependent: :destroy
|
||||
has_many :contact_inboxes, dependent: :destroy
|
||||
has_many :csat_survey_responses, dependent: :destroy
|
||||
has_many :inboxes, through: :contact_inboxes
|
||||
has_many :messages, as: :sender, dependent: :destroy
|
||||
has_many :notes, dependent: :destroy
|
||||
|
||||
@@ -60,6 +60,7 @@ class Conversation < ApplicationRecord
|
||||
belongs_to :campaign, optional: true
|
||||
|
||||
has_many :messages, dependent: :destroy, autosave: true
|
||||
has_one :csat_survey_response, dependent: :destroy
|
||||
|
||||
before_create :set_bot_conversation
|
||||
|
||||
|
||||
43
app/models/csat_survey_response.rb
Normal file
43
app/models/csat_survey_response.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: csat_survey_responses
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# feedback_message :text
|
||||
# rating :integer not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
# assigned_agent_id :bigint
|
||||
# contact_id :bigint not null
|
||||
# conversation_id :bigint not null
|
||||
# message_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_csat_survey_responses_on_account_id (account_id)
|
||||
# index_csat_survey_responses_on_assigned_agent_id (assigned_agent_id)
|
||||
# index_csat_survey_responses_on_contact_id (contact_id)
|
||||
# index_csat_survey_responses_on_conversation_id (conversation_id)
|
||||
# index_csat_survey_responses_on_message_id (message_id) UNIQUE
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (account_id => accounts.id)
|
||||
# fk_rails_... (assigned_agent_id => users.id)
|
||||
# fk_rails_... (contact_id => contacts.id)
|
||||
# fk_rails_... (conversation_id => conversations.id)
|
||||
# fk_rails_... (message_id => messages.id)
|
||||
#
|
||||
class CsatSurveyResponse < ApplicationRecord
|
||||
belongs_to :account
|
||||
belongs_to :conversation
|
||||
belongs_to :contact
|
||||
belongs_to :message
|
||||
belongs_to :assigned_agent, class_name: 'User', optional: true
|
||||
|
||||
validates :rating, presence: true, inclusion: { in: [1, 2, 3, 4, 5] }
|
||||
validates :account_id, presence: true
|
||||
validates :contact_id, presence: true
|
||||
validates :conversation_id, presence: true
|
||||
end
|
||||
@@ -79,6 +79,7 @@ class Message < ApplicationRecord
|
||||
belongs_to :sender, polymorphic: true, required: false
|
||||
|
||||
has_many :attachments, dependent: :destroy, autosave: true, before_add: :validate_attachments_limit
|
||||
has_one :csat_survey_response, dependent: :destroy
|
||||
|
||||
after_create :reopen_conversation,
|
||||
:notify_via_mail
|
||||
|
||||
@@ -71,6 +71,7 @@ class User < ApplicationRecord
|
||||
|
||||
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify
|
||||
alias_attribute :conversations, :assigned_conversations
|
||||
has_many :csat_survey_responses, foreign_key: 'assigned_agent_id', dependent: :nullify
|
||||
|
||||
has_many :inbox_members, dependent: :destroy
|
||||
has_many :inboxes, through: :inbox_members, source: :inbox
|
||||
|
||||
Reference in New Issue
Block a user