Sha256: b9e80bc5b7e119c10c009e0b8fa40f65f68296e4bc091b278efe84abae2eaf09

Contents?: true

Size: 1.15 KB

Versions: 142

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Renalware
  module Patients
    class WorryController < BaseController
      before_action :load_patient, only: :create

      # idempotent
      def create
        worry = Worry.find_or_create_by!(patient: patient) do |wor|
          wor.by = user
        end
        update_worry_notes_if_supplied(worry)
        redirect_back(fallback_location: patient_path(patient),
                      notice: t(".success", patient: patient))
      end

      # idempotent
      def destroy
        if (worry = patient.worry)
          authorize worry
          worry.destroy!
        else
          skip_authorization
        end
        redirect_back(fallback_location: patient_path(patient),
                      notice: t(".success", patient: patient))
      end

      private

      def update_worry_notes_if_supplied(worry)
        if worry_params[:notes].present?
          worry.update(worry_params.merge!(by: current_user))
        end
      end

      def user
        @user ||= Renalware::Patients.cast_user(current_user)
      end

      def worry_params
        params.require(:patients_worry).permit(:notes)
      end
    end
  end
end

Version data entries

142 entries across 142 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.1.0 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.167 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.166 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.165 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.164 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.163 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.162 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.161 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.160 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.159 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.158 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.157 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.156 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.155 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.153 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.152 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.151 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.149 app/controllers/renalware/patients/worry_controller.rb
renalware-core-2.0.148 app/controllers/renalware/patients/worry_controller.rb