Class: Services::FacilityMappingsController

Inherits:
ThirdPartyBaseController show all
Defined in:
app/controllers/services/facility_mappings_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::MAX_LIST_LENGTH

Instance Attribute Summary collapse

Attributes inherited from ThirdPartyBaseController

#third_party

Instance Method Summary collapse

Instance Attribute Details

#facility_mappingObject (readonly)

Returns the value of attribute facility_mapping.



4
5
6
# File 'app/controllers/services/facility_mappings_controller.rb', line 4

def facility_mapping
  @facility_mapping
end

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
# File 'app/controllers/services/facility_mappings_controller.rb', line 23

def create
  fm = CreateFacilityMappingContext.call(third_party, safe_params)
  if fm.errors.empty?
    render json: { id: fm.id }
  else
    render json: { validation_error: fm.errors.full_messages }, status: 403
  end
end

#destroyObject



41
42
43
44
# File 'app/controllers/services/facility_mappings_controller.rb', line 41

def destroy
  facility_mapping.destroy
  render json: { id: facility_mapping.id }
end

#indexObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/services/facility_mappings_controller.rb', line 9

def index
  if params[:configured_account_id]
     = ConfiguredAccount.find params[:configured_account_id]
    enabled_facility_ids = ApplicationApi.api_impl.(.).pluck(:id)
    @facility_mappings = FacilityMapping.where(facility_id: enabled_facility_ids).order("facility_code ASC")
  else
    @facility_mappings = third_party.facility_mappings
  end
end

#showObject



19
20
21
# File 'app/controllers/services/facility_mappings_controller.rb', line 19

def show
  # Nothing to do
end

#updateObject



32
33
34
35
36
37
38
39
# File 'app/controllers/services/facility_mappings_controller.rb', line 32

def update
  UpdateFacilityMappingContext.call(facility_mapping, safe_params)
  if facility_mapping.errors.empty?
    render json: { id: facility_mapping.id }
  else
    render json: { validation_error: facility_mapping.errors.full_messages }, status: 403
  end
end