diff --git a/app/controllers/super_admin/themes_controller.rb b/app/controllers/super_admin/themes_controller.rb index df1fa4f..5c8560e 100644 --- a/app/controllers/super_admin/themes_controller.rb +++ b/app/controllers/super_admin/themes_controller.rb @@ -66,7 +66,13 @@ end def extract - @theme = Theme.find(params[:id]) + @theme = Theme.find(extract_params[:id]) + @answers = @theme.answers + @answers = @answers.where(plan_id: extract_params[:plan_id]) if extract_params[:plan_id] + @answers = @answers.where(question_id: extract_params[:question_id]) if extract_params[:question_id] + @answers = @answers.since(extract_params[:start_date]) + @answers = @answers.until(extract_params[:end_date]) + render format: :json end @@ -76,5 +82,9 @@ def permitted_params params.require(:theme).permit(:title, :description) end + + def extract_params + params.permit(:id, :plan_id, :question_id, :start_date, :end_date) + end end end diff --git a/app/models/answer.rb b/app/models/answer.rb index 4e8a3e5..ccde9b5 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -30,6 +30,9 @@ :question, :user, :plan, :question_options, :notes, :note_ids, :id, :as => [:default, :admin] + scope :since, ->(date) { where('answers.created_at >= ?', date) if date } + scope :until, ->(date) { where('answers.created_at <= ?', date) if date } + ## # Validations # validates :user, :plan, :question, presence: true diff --git a/app/views/super_admin/themes/extract.jbuilder b/app/views/super_admin/themes/extract.jbuilder index 6f061ef..1c05f2d 100644 --- a/app/views/super_admin/themes/extract.jbuilder +++ b/app/views/super_admin/themes/extract.jbuilder @@ -1,7 +1,8 @@ json.theme @theme.title -json.answers @theme.answers do |a| +json.answers @answers do |a| json.id a.id json.answer a.text + json.created_at a.created_at json.question do json.id a.question.id json.title a.question.text