Files
nairobi/app/controllers/dashboard/achievements_controller.rb
Juan Salvador Pérez García 50f73abb0c Fixes #voodoorai2000 comments
Fixes some comments from #voodoorai2000 for the PR to consul
2018-07-27 16:30:03 +02:00

45 lines
1.4 KiB
Ruby

class Dashboard::AchievementsController < Dashboard::BaseController
include Dashboard::ExpectsDateRange
def index
authorize! :dashboard, proposal
render json: processed_groups
end
private
def processed_groups
grouped_results = groups
grouped_results.each do |key, results|
grouped_results[key] = {
executed_at: results.last.executed_at,
title: results.last.action.title
}
end
grouped_results
end
def groups
if params[:group_by] == 'week'
return executed_proposed_actions.group_by { |v| "#{v.executed_at.to_date.cweek}/#{v.executed_at.to_date.year}"}
end
if params[:group_by] == 'month'
return executed_proposed_actions.group_by { |v| "#{v.executed_at.to_date.year}-#{v.executed_at.to_date.month}"}
end
executed_proposed_actions.group_by { |a| a.executed_at.to_date }
end
def executed_proposed_actions
@executed_proposed_actions ||= Dashboard::ExecutedAction
.joins(:action)
.includes(:action)
.where(proposal: proposal)
.where(executed_at: start_date.beginning_of_day..end_date.end_of_day)
.where(dashboard_actions: { action_type: 0 })
.order(executed_at: :asc)
end
end