fix proficiency filter for quirk and standard artifacts
This commit is contained in:
parent
ab19403904
commit
693962ce3b
2 changed files with 8 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ module Api
|
|||
|
||||
@collection_artifacts = @collection_artifacts.where(artifact_id: params[:artifact_id]) if params[:artifact_id]
|
||||
@collection_artifacts = @collection_artifacts.where(element: params[:element]) if params[:element]
|
||||
@collection_artifacts = @collection_artifacts.by_proficiency(params[:proficiency]) if params[:proficiency].present?
|
||||
@collection_artifacts = @collection_artifacts.joins(:artifact).where(artifacts: { rarity: params[:rarity] }) if params[:rarity]
|
||||
|
||||
# Skill filters - each slot uses OR logic, slots combined with AND logic
|
||||
|
|
|
|||
|
|
@ -43,7 +43,13 @@ class CollectionArtifact < ApplicationRecord
|
|||
# Scopes
|
||||
scope :by_element, ->(el) { where(element: el) }
|
||||
scope :by_artifact, ->(artifact_id) { where(artifact_id: artifact_id) }
|
||||
scope :by_proficiency, ->(prof) { where(proficiency: prof) }
|
||||
# Filter by proficiency - handles both quirk (instance) and standard (artifact) proficiencies
|
||||
scope :by_proficiency, ->(prof) {
|
||||
joins(:artifact).where(
|
||||
'collection_artifacts.proficiency IN (?) OR (collection_artifacts.proficiency IS NULL AND artifacts.proficiency IN (?))',
|
||||
Array(prof), Array(prof)
|
||||
)
|
||||
}
|
||||
scope :by_rarity, ->(rar) { joins(:artifact).where(artifacts: { rarity: rar }) }
|
||||
scope :standard_only, -> { joins(:artifact).where(artifacts: { rarity: :standard }) }
|
||||
scope :quirk_only, -> { joins(:artifact).where(artifacts: { rarity: :quirk }) }
|
||||
|
|
|
|||
Loading…
Reference in a new issue