Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save properties #87

Open
antarr opened this issue Jun 20, 2021 · 0 comments
Open

Unable to save properties #87

antarr opened this issue Jun 20, 2021 · 0 comments

Comments

@antarr
Copy link

antarr commented Jun 20, 2021

I'm using typedstore with lockbox. When trying to assign the values in setting in a request it seems to work. Not getting any errors. But after going into the console and checking the value it doesn't seem to work, it's returning the default value.

ie.

User.last.language # => 'en-us'
# but 
User.last.city # => ""

controller

  def create
    user = User.find_by(q2_id: q2_id_param)
    if user.blank?
      user = User.find_or_initialize_by(
        email: q2_user_param[:email_address]
      )
      unless user.persisted?
        user.password = generated_password
        user.password_confirmation = generated_password
      end
      user.q2_id = q2_id_param
    end

    user.map_settings!(q2_user_param)
    user.reload

    render json: JSON.dump(
      user: {
        uuid: user.hp_user_uuid,
        auth_token: user.authentication_token
      }
    )
  end

having_settings.rby

module HavingSettings
  extend ActiveSupport::Concern

  included do
    encrypts :settings # , migrating: true

    typed_store :setting, coder: JSON do |s|
      s.string :address1, default: ''
      s.string :address2, default: ''
      s.string :city, default: ''
      s.string :customer_id, default: ''
      s.string :customer_name, default: ''
      s.string :customer_primary_cif, default: ''
      s.string :social_security_number, default: ''
      s.string :email_address, default: ''
      s.string :first_name, default: ''
      s.string :last_name, default: ''
      s.string :group_desc, default: ''
      s.string :group_id, default: ''
      s.string :home_phone, default: ''
      s.string :aba, default: ''
      s.string :hq_session_id, default: ''
      s.string :language, default: 'en-us'
      s.string :login_name, default: ''
      s.string :middle_name, default: ''
      s.string :mobile_phone, default: ''
      s.string :postal_code, default: ''
      s.string :ssn, default: ''
      s.string :state, default: ''
      s.string :user_logon_id, default: ''
      s.string :user_id, default: ''
      s.string :user_primary_cif, default: ''
      s.string :work_phone, default: ''
      s.string :ip_address, default: ''
      s.string :token, default: ''
      s.string :uuid, default: SecureRandom.uuid
      s.string :hp_user_uuid, default: SecureRandom.uuid
    end

    def map_settings!(data)
      update!(data.to_h)
    rescue StandardError => e
      Rails.logger.error(e)
      raise
    end
  end
end

body of postman request

{
    "user": {"city": "Houston",
    "state": "Texas",
    "first_name": "Antarr",
    "email_address": "user@email.com",
    "user_id": "q2-user-4"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant