Class: NPSSurveys::ApiInternal::ResponsesController
- Inherits:
-
Object
- Object
- NPSSurveys::ApiInternal::ResponsesController
- Defined in:
- app/controllers/nps_surveys/api_internal/responses_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/nps_surveys/api_internal/responses_controller.rb', line 5 def create response = create_survey_response return render json: ResponseSerializer.new(response).to_json if response.valid? render json: { error: { message: 'Unprocessable Entity', errors: response.try(:errors).try(:to_hash) } }, status:422 end |
#index ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/controllers/nps_surveys/api_internal/responses_controller.rb', line 17 def index responses = ::NPSSurveys::Response.where(user_id: NPSSurveys.current_user.call(self).id).map do |response| ResponseSerializer.new(response).to_json end render json: responses.to_json end |