feat: CSAT response public APIs (#2670)
This commit is contained in:
32
app/controllers/public/api/v1/csat_survey_controller.rb
Normal file
32
app/controllers/public/api/v1/csat_survey_controller.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class Public::Api::V1::CsatSurveyController < PublicController
|
||||
before_action :set_conversation
|
||||
before_action :set_message
|
||||
|
||||
def show; end
|
||||
|
||||
def update
|
||||
render json: { error: 'You cannot update the CSAT survey after 14 days' }, status: :unprocessable_entity and return if check_csat_locked
|
||||
|
||||
@message.update!(message_update_params[:message])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_conversation
|
||||
return if params[:id].blank?
|
||||
|
||||
@conversation = Conversation.find_by!(uuid: params[:id])
|
||||
end
|
||||
|
||||
def set_message
|
||||
@message = @conversation.messages.find_by!(content_type: 'input_csat')
|
||||
end
|
||||
|
||||
def message_update_params
|
||||
params.permit(message: [{ submitted_values: [:name, :title, :value, { csat_survey_response: [:feedback_message, :rating] }] }])
|
||||
end
|
||||
|
||||
def check_csat_locked
|
||||
(Time.zone.now.to_date - @message.created_at.to_date).to_i > 14
|
||||
end
|
||||
end
|
||||
1
app/views/public/api/v1/csat_survey/show.json.jbuilder
Normal file
1
app/views/public/api/v1/csat_survey/show.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! 'public/api/v1/models/csat_survey.json.jbuilder', resource: @message
|
||||
1
app/views/public/api/v1/csat_survey/update.json.jbuilder
Normal file
1
app/views/public/api/v1/csat_survey/update.json.jbuilder
Normal file
@@ -0,0 +1 @@
|
||||
json.partial! 'public/api/v1/models/csat_survey.json.jbuilder', resource: @message
|
||||
@@ -0,0 +1,5 @@
|
||||
json.id resource.id
|
||||
json.csat_survey_response resource.csat_survey_response
|
||||
json.inbox_avatar_url resource.inbox.avatar_url
|
||||
json.conversation_id resource.conversation_id
|
||||
json.created_at resource.created_at
|
||||
Reference in New Issue
Block a user