From 693962ce3b99ce7b05a1b1cad9a5f6dcba632206 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 19 Dec 2025 01:07:41 -0800 Subject: [PATCH] fix proficiency filter for quirk and standard artifacts --- app/controllers/api/v1/collection_artifacts_controller.rb | 1 + app/models/collection_artifact.rb | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/collection_artifacts_controller.rb b/app/controllers/api/v1/collection_artifacts_controller.rb index 14030b0..5da60d8 100644 --- a/app/controllers/api/v1/collection_artifacts_controller.rb +++ b/app/controllers/api/v1/collection_artifacts_controller.rb @@ -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 diff --git a/app/models/collection_artifact.rb b/app/models/collection_artifact.rb index 96f6300..2163a2f 100644 --- a/app/models/collection_artifact.rb +++ b/app/models/collection_artifact.rb @@ -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 }) }