include crew_total_score in gw events index

This commit is contained in:
Justin Edmund 2025-12-17 23:03:22 -08:00
parent 5afd31fdb6
commit 42f3d3a9cf
2 changed files with 16 additions and 1 deletions

View file

@ -19,6 +19,11 @@ module Api
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
field :participation, if: ->(_fn, _obj, options) { options[:participation].present? } do |_, options|
CrewGwParticipationBlueprint.render_as_hash(options[:participation], view: :summary)

View file

@ -10,7 +10,17 @@ module Api
# GET /gw_events
def index
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
# GET /gw_events/:id