Update party-related files for 1-index guidebooks
This commit is contained in:
parent
204e77e64e
commit
488c34388d
3 changed files with 25 additions and 13 deletions
|
|
@ -42,9 +42,9 @@ module Api
|
|||
|
||||
field :guidebooks do |p|
|
||||
{
|
||||
'0' => !p.guidebook0.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook0) : nil,
|
||||
'1' => !p.guidebook1.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook1) : nil,
|
||||
'2' => !p.guidebook2.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook2) : nil
|
||||
'2' => !p.guidebook2.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook2) : nil,
|
||||
'3' => !p.guidebook3.nil? ? GuidebookBlueprint.render_as_hash(p.guidebook3) : nil
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ module Api
|
|||
|
||||
# TODO: Validate accessory with job
|
||||
|
||||
return render json: PartyBlueprint.render(@party, view: :full, root: :party) if @party.save!
|
||||
|
||||
return render json: PartyBlueprint.render(@party, view: :full, root: :party) if @party.save
|
||||
|
||||
render_validation_error_response(@party)
|
||||
end
|
||||
|
||||
|
|
@ -241,8 +241,6 @@ module Api
|
|||
end
|
||||
|
||||
def party_params
|
||||
ap "Params are..."
|
||||
ap params
|
||||
return unless params[:party].present?
|
||||
|
||||
params.require(:party).permit(
|
||||
|
|
@ -266,9 +264,9 @@ module Api
|
|||
:button_count,
|
||||
:turn_count,
|
||||
:chain_count,
|
||||
:guidebook0_id,
|
||||
:guidebook1_id,
|
||||
:guidebook2_id
|
||||
:guidebook2_id,
|
||||
:guidebook3_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,11 +41,6 @@ class Party < ApplicationRecord
|
|||
class_name: 'JobSkill',
|
||||
optional: true
|
||||
|
||||
belongs_to :guidebook0,
|
||||
foreign_key: 'guidebook0_id',
|
||||
class_name: 'Guidebook',
|
||||
optional: true
|
||||
|
||||
belongs_to :guidebook1,
|
||||
foreign_key: 'guidebook1_id',
|
||||
class_name: 'Guidebook',
|
||||
|
|
@ -56,6 +51,11 @@ class Party < ApplicationRecord
|
|||
class_name: 'Guidebook',
|
||||
optional: true
|
||||
|
||||
belongs_to :guidebook3,
|
||||
foreign_key: 'guidebook3_id',
|
||||
class_name: 'Guidebook',
|
||||
optional: true
|
||||
|
||||
has_many :characters,
|
||||
foreign_key: 'party_id',
|
||||
class_name: 'GridCharacter',
|
||||
|
|
@ -95,6 +95,7 @@ class Party < ApplicationRecord
|
|||
|
||||
##### ActiveRecord Validations
|
||||
validate :skills_are_unique
|
||||
validate :guidebooks_are_unique
|
||||
|
||||
attr_accessor :favorited
|
||||
|
||||
|
|
@ -145,4 +146,17 @@ class Party < ApplicationRecord
|
|||
|
||||
errors.add(:job_skills, 'must be unique')
|
||||
end
|
||||
|
||||
def guidebooks_are_unique
|
||||
guidebooks = [guidebook1, guidebook2, guidebook3].compact
|
||||
return if guidebooks.uniq.length == guidebooks.length
|
||||
|
||||
guidebooks.each_with_index do |book, index|
|
||||
next if index.zero?
|
||||
|
||||
errors.add(:"guidebook#{index + 1}", 'must be unique') if guidebooks[0...index].include?(book)
|
||||
end
|
||||
|
||||
errors.add(:guidebooks, 'must be unique')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue