Class: CompanyParametersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/company_parameters_controller.rb

Instance Method Summary collapse

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#indexObject



11
12
13
14
15
16
17
# File 'app/controllers/company_parameters_controller.rb', line 11

def index
  data = CompanyParameter.where_procedure(company_id: current_company_id)

  render json: {
    data: data
  }
end

#update_from_table_editsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/company_parameters_controller.rb', line 19

def update_from_table_edits
  request.params[:rows_edits].each do |row_edits|
    row_hash = row_edits[:rowHash]
    edits = row_edits[:edits]

    company_parameter = current_company.company_parameters.find(row_hash[:company_parameter_id])

    attributes = edits.slice(:description, :active, :value).reject { |_, v| v.nil? }
    company_parameter.assign_attributes(attributes)
    company_parameter.write_proceudre!(user_name: current_user.truncated_email)
  end

  edits_count = request.params[:rows_edits].count

  render json: {
    message: edits_count > 1 ? I18n.t('messages.parameters_updated') : I18n.t('messages.parameter_updated')
  }
rescue ActiveRecord::RecordInvalid => e
  render json: {
    message: e.record.errors.full_messages.join(', ')
  }, status: :bad_request
end