hensei-api/app/models/crew.rb
Justin Edmund f2a058b6b2 add GW events and scoring system
- create gw_events, crew_gw_participations, gw_crew_scores, gw_individual_scores
- add models, blueprints, controllers for GW tracking
- add model specs and gw_events controller specs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 23:34:54 -08:00

36 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class Crew < ApplicationRecord
has_many :crew_memberships, dependent: :destroy
has_many :users, through: :crew_memberships
has_many :active_memberships, -> { where(retired: false) }, class_name: 'CrewMembership'
has_many :active_members, through: :active_memberships, source: :user
has_many :crew_invitations, dependent: :destroy
has_many :pending_invitations, -> { where(status: :pending) }, class_name: 'CrewInvitation'
has_many :crew_gw_participations, dependent: :destroy
has_many :gw_events, through: :crew_gw_participations
validates :name, presence: true, length: { maximum: 100 }
validates :gamertag, length: { maximum: 50 }, allow_nil: true
validates :granblue_crew_id, uniqueness: true, allow_nil: true
def captain
crew_memberships.find_by(role: :captain, retired: false)&.user
end
def vice_captains
crew_memberships.where(role: :vice_captain, retired: false).includes(:user).map(&:user)
end
def officers
crew_memberships.where(role: [:captain, :vice_captain], retired: false).includes(:user).map(&:user)
end
def member_count
active_memberships.count
end
def blueprint
CrewBlueprint
end
end