Skip to content

Unable to save properties #87

Description

@antarr

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"}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions