Skip to content

Commit

Permalink
feat: Adds "questionnaire_id" to User.as_json (#394)
Browse files Browse the repository at this point in the history
* feat: Adds "questionnaire_id" to User.as_json

* Fixes Hound issues
  • Loading branch information
cbaudouinjr authored Nov 8, 2020
1 parent bf225b8 commit 774de1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ def logged_in
end

def show
respond_to do |format|
format.json { render json: current_user }
end
render json: current_user
end
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,10 @@ def self.non_organizer
def self.without_questionnaire
non_organizer.left_outer_joins(:questionnaire).where(questionnaires: { id: nil })
end

def as_json(options = {})
result = super
result['questionnaire_id'] = Questionnaire.where(user_id: id).any? ? Questionnaire.where(user_id: id).first.id : nil
result
end
end

0 comments on commit 774de1e

Please sign in to comment.