Class: Ecoportal::API::GraphQL::Input::ContractorEntity::Update

Inherits:
Create show all
Defined in:
lib/ecoportal/api/graphql/input/contractor_entity/update.rb

Constant Summary collapse

ID_DIFF_FIELDS =
%i[associatedPeopleIds leadContractorIds].freeze

Constants included from Common::GraphQL::Model::Diffable

Common::GraphQL::Model::Diffable::DIFF_CLASS

Class Method Summary collapse

Methods included from Base::ContractorEntity::MemberChanges

#associate, #dissassociate, #lead!, #unlead!

Methods included from Concerns::SnakeCamelAccess

#method_missing, #respond_to_missing?

Methods included from Common::GraphQL::Model::AsInput

#as_input

Methods included from Common::GraphQL::Model::Diffable

#as_update, #dirty?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ecoportal::API::GraphQL::Concerns::SnakeCamelAccess

Class Method Details

.from_model(model, **kargs) ⇒ Object

Overrides Logic::Input.from_model to reshape array fields into IdDiffInput format: { additions: [...], removals: [...] } Array fields are stripped from the flat diff, so we compare doc vs original_doc directly rather than relying on the diff hash.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ecoportal/api/graphql/input/contractor_entity/update.rb', line 19

def from_model(model, **kargs)
  diff = Logic::Input.from_model(model, **kargs)

  ID_DIFF_FIELDS.each do |field|
    key      = field.to_s
    current  = Array(model.doc[key])
    original = Array(model.original_doc[key])
    next if current == original

    diff       ||= {}
    diff[:id]  ||= model.id
    diff[field]  = { additions: current - original, removals: original - current }
  end

  diff
end