Module: Vet360::Writeable
- Extended by:
- ActiveSupport::Concern
- Included in:
- V0::Profile::AddressesController, V0::Profile::EmailAddressesController, V0::Profile::PermissionsController, V0::Profile::TelephonesController, V0::Profile::TransactionsController
- Defined in:
- app/controllers/concerns/vet360/writeable.rb
Instance Method Summary collapse
- #add_effective_end_date(params) ⇒ Object private
- #build_record(type, params) ⇒ Object private
- #invalidate_cache ⇒ Object
- #render_new_transaction!(type, response) ⇒ Object private
- #service ⇒ Object private
- #validate!(record) ⇒ Object private
-
#write_to_vet360_and_render_transaction!(type, params, http_verb: 'post') ⇒ Response
For the passed VAProfile model type and params, it: - builds and validates a VAProfile models - POSTs/PUTs the model data to VAProfile - creates a new AsyncTransaction db record, based on the type - renders the transaction through the base serializer.
- #write_valid_record!(http_verb, type, record) ⇒ Object private
Instance Method Details
#add_effective_end_date(params) ⇒ Object (private)
84 85 86 87 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 84 def add_effective_end_date(params) params[:effective_end_date] = Time.now.utc.iso8601 params end |
#build_record(type, params) ⇒ Object (private)
41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 41 def build_record(type, params) # This needs to be refactored after V2 upgrade is complete model = if type == 'address' && Flipper.enabled?(:va_v3_contact_information_service, @current_user) 'VAProfile::Models::V3::Address' else "VAProfile::Models::#{type.capitalize}" end model.constantize .new(params) .set_defaults(@current_user) end |
#invalidate_cache ⇒ Object
31 32 33 34 35 36 37 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 31 def invalidate_cache if Flipper.enabled?(:va_v3_contact_information_service, @current_user) VAProfileRedis::V2::Cache.invalidate(@current_user) else VAProfileRedis::Cache.invalidate(@current_user) end end |
#render_new_transaction!(type, response) ⇒ Object (private)
77 78 79 80 81 82 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 77 def render_new_transaction!(type, response) transaction = "AsyncTransaction::VAProfile::#{type.capitalize}Transaction".constantize.start( @current_user, response ) render json: AsyncTransaction::BaseSerializer.new(transaction).serializable_hash end |
#service ⇒ Object (private)
63 64 65 66 67 68 69 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 63 def service if Flipper.enabled?(:va_v3_contact_information_service, @current_user) VAProfile::V2::ContactInformation::Service.new @current_user else VAProfile::ContactInformation::Service.new @current_user end end |
#validate!(record) ⇒ Object (private)
53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 53 def validate!(record) return if record.valid? PersonalInformationLog.create!( data: record.to_h, error_class: "#{record.class} ValidationError" ) raise Common::Exceptions::ValidationErrors, record end |
#write_to_vet360_and_render_transaction!(type, params, http_verb: 'post') ⇒ Response
For the passed VAProfile model type and params, it:
- builds and validates a VAProfile models
- POSTs/PUTs the model data to VAProfile
- creates a new AsyncTransaction db record, based on the type
- renders the transaction through the base serializer
22 23 24 25 26 27 28 29 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 22 def write_to_vet360_and_render_transaction!(type, params, http_verb: 'post') output_rails_logs = Flipper.enabled?(:va_v3_contact_information_service, @current_user) record = build_record(type, params) validate!(record) response = write_valid_record!(http_verb, type, record) Rails.logger.info('CI V2') if output_rails_logs render_new_transaction!(type, response) end |
#write_valid_record!(http_verb, type, record) ⇒ Object (private)
71 72 73 74 75 |
# File 'app/controllers/concerns/vet360/writeable.rb', line 71 def write_valid_record!(http_verb, type, record) # This will be removed after the upgrade. Permission was removed in the upgraded service. # Permissions are not used in ContactInformationV1 either. service.send("#{http_verb}_#{type.downcase}", record) end |