Sha256: 1053154747f0025795827c20144756631a5ccd693c991d82e220542708e71836

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/virology"

module Renalware
  module Virology
    class VaccinationTypesController < BaseController
      def index
        types = VaccinationType.with_deleted.ordered
        authorize types
        render locals: { types: types }
      end

      def edit
        type = find_and_authorise_type
        render locals: { type: type }
      end

      def update
        type = find_and_authorise_type
        if type.update(type_params)
          redirect_to virology_vaccination_types_path
        else
          render :edit, locals: { type: type }
        end
      end

      def new
        type = VaccinationType.new
        authorize type
        render locals: { type: type }
      end

      def create
        type = VaccinationType.new(type_params)
        authorize type
        if type.save
          redirect_to virology_vaccination_types_path
        else
          render :new, locals: { type: type }
        end
      end

      def destroy
        find_and_authorise_type.destroy!
        redirect_to virology_vaccination_types_path
      end

      def sort
        authorize VaccinationType, :sort?
        ids = params[:virology_vaccination_type]
        VaccinationType.sort(ids)
        render json: ids
      end

      private

      def find_and_authorise_type
        VaccinationType.find(params[:id]).tap { |type| authorize type }
      end

      def type_params
        params
          .require("virology_vaccination_type")
          .permit(:name, :code, :position)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/virology/vaccination_types_controller.rb
renalware-core-2.1.0 app/controllers/renalware/virology/vaccination_types_controller.rb
renalware-core-2.0.167 app/controllers/renalware/virology/vaccination_types_controller.rb
renalware-core-2.0.166 app/controllers/renalware/virology/vaccination_types_controller.rb
renalware-core-2.0.165 app/controllers/renalware/virology/vaccination_types_controller.rb