include crew_total_score in gw events index
This commit is contained in:
parent
5afd31fdb6
commit
42f3d3a9cf
2 changed files with 16 additions and 1 deletions
|
|
@ -19,6 +19,11 @@ module Api
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Include crew's total score if participation data is provided
|
||||||
|
field :crew_total_score, if: ->(_fn, event, options) { options[:participations]&.key?(event.id) } do |event, options|
|
||||||
|
options[:participations][event.id]&.total_individual_honors
|
||||||
|
end
|
||||||
|
|
||||||
view :with_participation do
|
view :with_participation do
|
||||||
field :participation, if: ->(_fn, _obj, options) { options[:participation].present? } do |_, options|
|
field :participation, if: ->(_fn, _obj, options) { options[:participation].present? } do |_, options|
|
||||||
CrewGwParticipationBlueprint.render_as_hash(options[:participation], view: :summary)
|
CrewGwParticipationBlueprint.render_as_hash(options[:participation], view: :summary)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,17 @@ module Api
|
||||||
# GET /gw_events
|
# GET /gw_events
|
||||||
def index
|
def index
|
||||||
events = GwEvent.order(start_date: :desc)
|
events = GwEvent.order(start_date: :desc)
|
||||||
render json: GwEventBlueprint.render(events, root: :gw_events)
|
|
||||||
|
# If user has a crew, include participation data for each event
|
||||||
|
participations_by_event = {}
|
||||||
|
if current_user&.crew
|
||||||
|
participations = current_user.crew.crew_gw_participations.includes(:gw_individual_scores)
|
||||||
|
participations.each do |p|
|
||||||
|
participations_by_event[p.gw_event_id] = p
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: GwEventBlueprint.render(events, root: :gw_events, participations: participations_by_event)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /gw_events/:id
|
# GET /gw_events/:id
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue