hensei-api/app/models/grid_summon.rb
Justin Edmund d2c5455120
Add support for inclusions/exclusions (#124)
* Remove ap call

* Fix remix render method

* Downcase username on db end

There was a bug where users with capital letters in their name could not access their profiles after we tried to make things case insensitive.

* Remove ap call and unused code

* Add granblue.team to cors

This works now!

* Implement all-entity search to support tagging objects (#117)

* Add table for multisearch

* Add new route for searching all entities

* Make models multisearchable

We're going to start with Character, Summon, Weapon and Jobs

* Add method to Search controller

This will search with trigram first, and then if there aren't enough results, search with prefixed text search

* Add support for Japanese all-entity search

* Update grid_summons_controller.rb

Set the proper uncap level for transcended summons

* Search is broken in Japanese!

* Grid model object updates

* Adds has_one association to canonical objects
* GridWeapon is_mainhand refactored
* GridCharacter add_awakening refactored

* (WIP) Add support for inclusion/exclusion + refactor

This commit adds basic support for including/excluding objects from collection filters. There is also a refactor of the filter logic as a whole. It is only implemented in `teams` for now and is a work in progress.

* Update multisearch for exclusions

* Add nicknames to the index for multisearchable
2023-08-21 20:01:15 -07:00

46 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class GridSummon < ApplicationRecord
belongs_to :party,
counter_cache: :summons_count,
inverse_of: :summons
validates_presence_of :party
has_one :object, class_name: 'Summon', foreign_key: :id, primary_key: :summon_id
validate :compatible_with_position, on: :create
validate :no_conflicts, on: :create
def summon
Summon.find(summon_id)
end
def blueprint
GridSummonBlueprint
end
# Returns conflicting summons if they exist
def conflicts(party)
return unless summon.limit
party.summons.find do |grid_summon|
return unless grid_summon.id
grid_summon if summon.id == grid_summon.summon.id
end
end
private
# Validates whether there is a conflict with the party
def no_conflicts
# Check if the grid summon conflicts with any of the other grid summons in the party
errors.add(:series, 'must not conflict with existing summons') unless conflicts(party).nil?
end
# Validates whether the summon can be added to the desired position
def compatible_with_position
return unless [4, 5].include?(position.to_i) && !summon.subaura
errors.add(:position, 'must have subaura for position')
end
end